Close the main window and open a new one - PyQt

*爱你&永不变心* 提交于 2019-12-30 18:27:49

问题


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 tried every way I could think of without success (with some resulting in segmentation fault). I need to do this because the new window will have some features according to the parameters that are passed.


回答1:


How about this:

....
....

def selectMode( self ):
    self.close()
    self.field_params = params

    self.show()



回答2:


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_())


来源:https://stackoverflow.com/questions/13105226/close-the-main-window-and-open-a-new-one-pyqt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!