-2

Here is the code open.py (main file) that opens a login page that has a button which when clicked closes the login page and opens a menu page:

from PyQt4 import QtGui
import sys
from loginpage import Ui_loginPage
from menu import Ui_Menu

class Form1(QtGui.QWidget, Ui_loginPage):
    def __init__(self,parent=None):
        QtGui.QWidget.__init__(self,parent)
        self.setupUi(self)
        self.login.clicked.connect(self.handleButton)
        self.window2 = None

    def handleButton(self):
        self.close()
        if self.window2 is None:
            self.window2 = menu(self)
        self.window2.show()
        sys.exit(app.exec_())


class menu(QtGui.QWidget, Ui_Menu):     
    def __init__(self,parent=None):
        QtGui.QWidget.__init__(self,parent)
        self.setupUi(self)

if __name__ == '__main__':       

    app = QtGui.QApplication(sys.argv)
    window = Form1()
    window.show()
    sys.exit(app.exec_())

The code runs fine without any error, but when i click the login button, the login page closes but the menu page doesn't appear. It just doesn't show at all.

ekhumoro
  • 115,249
  • 20
  • 229
  • 336

1 Answers1

0

If the menu window is a child of the Form1 window, it will be hidden when the Form1 window is closed - so don't give it a parent. You also shouldn't be calling sys.exit(app.exec_()) again, so your code should look like this:

class Form1(QtGui.QWidget, Ui_loginPage):
    ...

    def handleButton(self):
        self.close()
        if self.window2 is None:
            self.window2 = menu()
        self.window2.show()

PS: please see this answer for a more complete example of how to implement a login dialog in PyQt.

Community
  • 1
  • 1
ekhumoro
  • 115,249
  • 20
  • 229
  • 336