问题
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