Close the main window and open a new one - PyQt

前端 未结 2 871
野性不改
野性不改 2021-01-12 14:28

In PyQt, is it any way to close the main window and open a new one?

In particular, I am trying to close a window and open the same window all over again. I\'ve trie

相关标签:
2条回答
  • 2021-01-12 14:59

    How about this:

    ....
    ....
    
    def selectMode( self ):
        self.close()
        self.field_params = params
    
        self.show()
    
    0 讨论(0)
  • 2021-01-12 14:59

    Well, somehow soon after posting I managed to make it work. Here is the code:

    class GameWindow(QtGui.QMainWindow):
    
    def __init__(self, field_params):
        super(GameWindow, self).__init__()
        self.field_params = field_params
    
        #some code that ends up calling selectMode
    
        def selectMode(self):
            self.close()
            self.__init__(params)
    
    def main():
        app = QtGui.QApplication(sys.argv)
        game_window = GameWindow()
        sys.exit(app.exec_())
    
    0 讨论(0)
提交回复
热议问题