This is how I restart TicTacToe game in PySide (it should be the same in PyQt):
I have a single class - a QWidget
class - in which is coded the Tic Tac Toe game. To restart the application I use:
import subprocess
a QPushButton()
like so:
self.button = QPushButton("Restart", self)
the connection of the button
to Slot
:
self.buton.clicked.connect(self.restartGame)
the Slot
for this button, like so:
def restartGame(self):
self.close()
subprocess.call("python" + " TicTAcToe.py", shell=True)
All these are in the same - single - class. And what these do: close the active window of the game and create a new one.
How this code looks in the TicTacToe class:
import subprocess
class TicTacToe(QWidget):
def __init__(self):
QWidget.__init__(self)
self.button = QPushButton("Restart", self)
self.buton.clicked.connect(self.restartGame)
def restartGame(self):
self.close()
subprocess.call("python" + " TicTacToe.py", shell=True)
def main():
app = QApplication(sys.argv)
widget = TicTacToe()
widget.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
EDIT
I know this doesn't answer the question (it doesn't restart a QApplication
), but I hope this helps those who want to restart their QWidget
single class.