Making a program and ive made a login system to connect the user to the main menu. So far ive got it to work but not to what i like. My code launches the program well but im having trouble with the if name == 'main': subroutine. My problem is very similar to Login dialog PyQt
Login excerpt
class Ui_Login(QtGui.QDialog):
def __init__(self):
QtGui.QDialog.__init__(self)
self.dbu = db.DatabaseUtility('UsernamePassword_DB', 'masterTable')
self.setupUi(self)
self.confirm = None
Mainwidget exceprt
class MainWidget(QWidget):
def __init__(self, parent=None):
super(MainWidget, self).__init__(parent)
self.stack = QStackedWidget()
layout = QVBoxLayout(self)
layout.addWidget(self.stack)
self.setGeometry(300, 300, 350, 250)
The problem arises when i get to the name section. if name == 'main':
import sys
app = QtGui.QApplication(sys.argv)
if Ui_Login().exec_() == QtGui.QDialog.Accepted:
sys.exit()
w = MainWidget()
w.show()
sys.exit()
This If correct username and password are entered, then main window is shown. But, the login form stays active, and if I close it, the main window will also close. I also tried another method
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
ex = Ui_Login()
ex.show()
sys.exit(app.exec_())
app = QApplication(sys.argv)
w = MainWidget()
w.show()
app.exec_()
sys.exit()
This meant that i would login as normal and the main window would come up but however the buttons wasn't working as it was not connecting to the other form. So the main widget class wasn't working. i tried again
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
ex = Ui_Login()
w = MainWidget()
ex.show()
w.show()
sys.exit(app.exec_())
sys.exit()
app = QApplication(sys.argv)
So this meant both the login dialog and the main window would load at the same time. However the button would work on the mainwindow. However it was not connected to my login system.
So the question how can i connect both the login system and the mainwindow together. Hopefully this question wasn't long and unwieldy