原谅我让这个问题变得过于复杂,这就是它的发生方式。所以我有这两个类,一个是windowm,另一个是modelm,我想让它在每当newGame()被调用时重新启动,所以这里有一些代码片段:
class windowm(QMainWindow):
def __init__(self):
super(windowm, self).__init__()
# a generic widget for the center of the window
widget = QWidget()
self.setCentralWidget(widget)
和其他班级:
class Model:
def __init__(self):
# setup is just starting a new game, so use that method
self.newGame()
def newGame(self):
super(windowm, self).__init__()
是的,我知道这很复杂,请原谅我,这就是分配的方式。因此,我了解在我得到一个烦人的独特场景之前已经解决了这一问题。因此,如您在第二段代码中所见,我正尝试使其跳回“ windowM”类并进入函数[[init(self)以重新启动游戏。请帮忙,谢谢!
我认为您虽然想更改游戏类别,所以从其他类别开始新游戏更容易。
class Model:
def startNewGame(self):
# setup is just starting a new game, so use that method
self.newGame()
def newGame(self):
super(windowm, self).__init__()
然后可以这样使用:
class windowm(QMainWindow): def __init__(self): super(windowm, self).__init__() # a generic widget for the center of the window widget = QWidget() self.setCentralWidget(widget) # create an instance of the other class ng = Model() # start a new game ng.startNewGame()