0

I need to make a login program that has a register function but I cannot open the register window from my main window. My goal is to get the register function from the main window code to open the register window so that I can use it.

I have no clue as to why; I've scoured the depths of this place in search of an answer but alas I have no luck.

Main window

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'mainwindow.ui'
#
# Created by: PyQt4 UI code generator 4.11.4
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui
from BlankSignup import SignUp

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)

class Login(object):
    def __init__(QtGui):
        usernames = ['a']
    def setupUi(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.setEnabled(True)
        MainWindow.resize(243, 252)
        palette = QtGui.QPalette()
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
        MainWindow.setPalette(palette)
        MainWindow.setTabShape(QtGui.QTabWidget.Triangular)
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
        self.gridLayoutWidget = QtGui.QWidget(self.centralwidget)
        self.gridLayoutWidget.setGeometry(QtCore.QRect(10, 10, 223, 189))
        self.gridLayoutWidget.setObjectName(_fromUtf8("gridLayoutWidget"))
        self.gridLayout = QtGui.QGridLayout(self.gridLayoutWidget)
        self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
        self.horizontalLayout = QtGui.QHBoxLayout()
        self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
        self.login_button = QtGui.QPushButton(self.gridLayoutWidget)
        palette = QtGui.QPalette()
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
        self.login_button.setPalette(palette)
        self.login_button.setObjectName(_fromUtf8("login_button"))
        self.horizontalLayout.addWidget(self.login_button)
        self.register_button = QtGui.QPushButton(self.gridLayoutWidget)
        self.register_button.setDefault(False)
        self.register_button.setObjectName(_fromUtf8("register_button"))
        self.horizontalLayout.addWidget(self.register_button)
        self.gridLayout.addLayout(self.horizontalLayout, 4, 0, 1, 2)
        self.signin_password_label = QtGui.QLabel(self.gridLayoutWidget)
        self.signin_password_label.setObjectName(_fromUtf8("signin_password_label"))
        self.gridLayout.addWidget(self.signin_password_label, 3, 0, 1, 1)
        self.signin_password = QtGui.QLineEdit(self.gridLayoutWidget)
        self.signin_password.setObjectName(_fromUtf8("signin_password"))
        self.gridLayout.addWidget(self.signin_password, 3, 1, 1, 1)
        self.signin_username = QtGui.QLineEdit(self.gridLayoutWidget)
        self.signin_username.setObjectName(_fromUtf8("signin_username"))
        self.gridLayout.addWidget(self.signin_username, 2, 1, 1, 1)
        self.singin_username_label = QtGui.QLabel(self.gridLayoutWidget)
        self.singin_username_label.setObjectName(_fromUtf8("singin_username_label"))
        self.gridLayout.addWidget(self.singin_username_label, 2, 0, 1, 1)
        self.signin_title = QtGui.QLabel(self.gridLayoutWidget)
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("Small Fonts"))
        font.setPointSize(72)
        self.signin_title.setFont(font)
        self.signin_title.setObjectName(_fromUtf8("signin_title"))
        self.gridLayout.addWidget(self.signin_title, 1, 0, 1, 2)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtGui.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 243, 21))
        self.menubar.setObjectName(_fromUtf8("menubar"))
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtGui.QStatusBar(MainWindow)
        self.statusbar.setObjectName(_fromUtf8("statusbar"))
        MainWindow.setStatusBar(self.statusbar)


        self.register_button.clicked.connect(self.register)
        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
        self.login_button.setText(_translate("MainWindow", "Login", None))
        self.register_button.setText(_translate("MainWindow", "Register", None))
        self.signin_password_label.setText(_translate("MainWindow", "<html><head/><body><p><span style=\" font-size:10pt; color:#ffffff;\">password:</span></p></body></html>", None))
        self.singin_username_label.setText(_translate("MainWindow", "<html><head/><body><p><span style=\" font-size:10pt; color:#ffffff;\">username:</span></p></body></html>", None))
        self.signin_title.setText(_translate("MainWindow", "<html><head/><body><p align=\"center\"><span style=\" color:#ffffff;\">Blank</span></p></body></html>", None))
    def register(self):
         pass
    def login(self):
        pass
if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    MainWindow = QtGui.QMainWindow()
    ui = Login()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())

Register window

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'signupwindowS.ui'
#
# Created by: PyQt4 UI code generator 4.11.4
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)

class SignUp(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(243, 250)
        palette = QtGui.QPalette()
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
        MainWindow.setPalette(palette)
        MainWindow.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
        MainWindow.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
        self.gridLayoutWidget = QtGui.QWidget(self.centralwidget)
        self.gridLayoutWidget.setGeometry(QtCore.QRect(10, 10, 222, 191))
        self.gridLayoutWidget.setObjectName(_fromUtf8("gridLayoutWidget"))
        self.gridLayout = QtGui.QGridLayout(self.gridLayoutWidget)
        self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
        self.signup_username = QtGui.QLineEdit(self.gridLayoutWidget)
        self.signup_username.setObjectName(_fromUtf8("signup_username"))
        self.gridLayout.addWidget(self.signup_username, 2, 1, 1, 1)
        self.signup_password_label = QtGui.QLabel(self.gridLayoutWidget)
        self.signup_password_label.setObjectName(_fromUtf8("signup_password_label"))
        self.gridLayout.addWidget(self.signup_password_label, 3, 0, 1, 1)
        self.signup_password = QtGui.QLineEdit(self.gridLayoutWidget)
        self.signup_password.setObjectName(_fromUtf8("signup_password"))
        self.gridLayout.addWidget(self.signup_password, 3, 1, 1, 1)
        self.signup_confirmpassword = QtGui.QLineEdit(self.gridLayoutWidget)
        self.signup_confirmpassword.setObjectName(_fromUtf8("signup_confirmpassword"))
        self.gridLayout.addWidget(self.signup_confirmpassword, 4, 1, 1, 1)
        self.signup_confirmpassword_label = QtGui.QLabel(self.gridLayoutWidget)
        self.signup_confirmpassword_label.setTextFormat(QtCore.Qt.AutoText)
        self.signup_confirmpassword_label.setObjectName(_fromUtf8("signup_confirmpassword_label"))
        self.gridLayout.addWidget(self.signup_confirmpassword_label, 4, 0, 1, 1)
        self.signup_username_label = QtGui.QLabel(self.gridLayoutWidget)
        self.signup_username_label.setObjectName(_fromUtf8("signup_username_label"))
        self.gridLayout.addWidget(self.signup_username_label, 2, 0, 1, 1)
        self.signup_title = QtGui.QLabel(self.gridLayoutWidget)
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("Small Fonts"))
        font.setPointSize(72)
        self.signup_title.setFont(font)
        self.signup_title.setObjectName(_fromUtf8("signup_title"))
        self.gridLayout.addWidget(self.signup_title, 0, 0, 1, 2)
        self.horizontalLayout = QtGui.QHBoxLayout()
        self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
        self.submit_button = QtGui.QPushButton(self.gridLayoutWidget)
        palette = QtGui.QPalette()
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
        self.submit_button.setPalette(palette)
        self.submit_button.setObjectName(_fromUtf8("submit_button"))
        self.horizontalLayout.addWidget(self.submit_button)
        self.cancle_button = QtGui.QPushButton(self.gridLayoutWidget)
        self.cancle_button.setDefault(False)
        self.cancle_button.setObjectName(_fromUtf8("cancle_button"))
        self.horizontalLayout.addWidget(self.cancle_button)
        self.gridLayout.addLayout(self.horizontalLayout, 5, 0, 1, 2)
        self.signup_subtitle = QtGui.QLabel(self.gridLayoutWidget)
        self.signup_subtitle.setObjectName(_fromUtf8("signup_subtitle"))
        self.gridLayout.addWidget(self.signup_subtitle, 1, 0, 1, 2)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtGui.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 243, 21))
        self.menubar.setObjectName(_fromUtf8("menubar"))
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtGui.QStatusBar(MainWindow)
        self.statusbar.setObjectName(_fromUtf8("statusbar"))
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(_translate("MainWindow", "Blank", None))
        self.signup_password_label.setText(_translate("MainWindow", "<html><head/><body><p><span style=\" color:#ffffff;\">new password</span></p></body></html>", None))
        self.signup_confirmpassword_label.setText(_translate("MainWindow", "<html><head/><body><p><span style=\" color:#ffffff;\">confirm password</span></p></body></html>", None))
        self.signup_username_label.setText(_translate("MainWindow", "<html><head/><body><p><span style=\" color:#ffffff;\">new username</span></p></body></html>", None))
        self.signup_title.setText(_translate("MainWindow", "<html><head/><body><p align=\"center\"><span style=\" font-size:24pt; color:#ffffff;\">Blank sign up</span></p></body></html>", None))
        self.submit_button.setText(_translate("MainWindow", "Submit", None))
        self.cancle_button.setText(_translate("MainWindow", "Cancel", None))
        self.signup_subtitle.setText(_translate("MainWindow", "<html><head/><body><p align=\"center\"><span style=\" font-size:12pt; color:#ffffff;\">put in information below</span></p></body></html>", None))


if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    MainWindow = QtGui.QMainWindow()
    ui = SignUp()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())
halfer
  • 19,824
  • 17
  • 99
  • 186
  • You would get more attention and, consequently better chances of a good answer to your questions, if you tried to edit so that you are a little more to the point. Posting smaller bits of code would be a good start. This is a good read: [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) – Thanos May 08 '16 at 21:09

1 Answers1

0
def registerFunction():
    s = SignUp()
    s.show()
    return s

EDIT:

at the first line of the function we created an instance of your SignUp form then call its member slot function show() to show the form, at the end of the function we return the instance of your SignUp form.

Now when you call this registerFunction() you will notice that the SignUp window is closing immediately, because the SignUp instance we created inside that function is automatically destroyed when goes out of scope

registerFunction() 
//destroyed, out of scope

to prevent this from happening you must keep a variable from your class that will reference this function.

(lets say we name it holder) Now we do:

holder = registerFunction()
Lorence Hernandez
  • 1,189
  • 12
  • 23