python - PyQt5: Object has no attribute 'exec_' with two main windows -
i new pyqt, when creating ui files, copied 1 mainwindow (mainfile.ui) , changed produce ui file (intro.ui). know not way create ui files, gives error: object has no attribute 'exec_'.
here code:
mainfile = "mainfile.ui"  ui_mainwindow, qtbaseclass = uic.loaduitype(mainfile)  fileintro = "intro.ui"   ui_windowintro,_ = uic.loaduitype(fileintro)  class mainwindow(qtwidgets.qmainwindow, ui_mainwindow):      def __init__(self):         qtwidgets.qmainwindow.__init__(self)         ui_mainwindow.__init__(self)         self.setupui(self)         self.buttonintro.clicked.connect(self.openwindowintro)     def openwindowintro(self):         s = windowintro()         s.show()         s.exec_() #here problem.  class windowintro(qtwidgets.qmainwindow, ui_windowintro):      def __init__(self):         qtwidgets.qmainwindow.__init__(self)         ui_windowintro.__init__(self)         self.setupui(self)         #close window         self.button2.clicked.connect(self.close)      def close(self):         self.close()  if __name__ == "__main__":      app = 0 # if not core die      app = qtwidgets.qapplication(sys.argv)      if login():          window = mainwindow()          window.show()          sys.exit(app.exec_()) can me solve problem. once python console shows attributeerror, kernel die.
this 1 works fine,thanks help:
mainfile = "mainfile.ui"
ui_mainwindow, qtbaseclass = uic.loaduitype(mainfile)
fileintro = "intro.ui"
ui_windowintro,_ = uic.loaduitype(fileintro)
class mainwindow(qtwidgets.qmainwindow, ui_mainwindow):
def __init__(self):     qtwidgets.qmainwindow.__init__(self)     ui_mainwindow.__init__(self)     self.setupui(self)     self.buttonintro.clicked.connect(self.openwindowintro) def openwindowintro(self):     self.anotherwindow = windowintro()     self.anotherwindow.close() class windowintro(qtwidgets.qmainwindow, ui_windowintro):
def __init__(self):     qtwidgets.qmainwindow.__init__(self)     ui_windowintro.__init__(self)     self.setupui(self)     #close window     self.button2.clicked.connect(self.close)  def close(self):     self.close() if name == "main":
app = 0 # if not core die  app = qtwidgets.qapplication(sys.argv)  if login():      window = mainwindow()      window.show()      sys.exit(app.exec_()) 
Comments
Post a Comment