pyqt5 Method for Multi Window Jump

  • 2021-06-28 13:36:10
  • OfStack

Today, I encountered a problem when I made a multi-page jump in pyqt5. If I click the button button, the program will crash.Checked on the web, it should be that when window A calls window B, the two windows cannot be of the same type.When I wrote, I wrote A and B as QWidget at the same time.After changing the window B to Dialog type, you can call it successfully.

The specific code goes on, write a general template as follows:


class A(QWidget):  
  def __init__(self):  
    ... ellipsis ...  
    self.btn = QPushButton(' Jump button ')  
  def initUI(self):  
    pass 
 
class B(QDialog):  
  def __init__(self):  
    pass
  def initUI(self):  
    pass 
  
if __name__ == '__main__':  
  app = QApplication(sys.argv)  
  a = A()  
  b = B()  
  a.show()  
  a.btn.clicked.connect(b.show)  
  app.exec_() 

Related articles: