At the end of my program execution, I want a popup message to appear that has a button which can re-run a program. Obviously, I will have setup a function that the button calls
This is potentially an over-simple approach, but say your existing program looks something like:
def my_app():
# Code goes here
if __name__ == "__main__":
my_app()
Instead wrap it like this:
def my_app():
print("App is running!")
# Your app code goes here
print("App is exiting!")
# On exit popup a prompt where selecting 'restart' sets restart_on_exit to True
# Replace input() with a popup as required
if input("Type y to restart the app! ").lower() == "y":
return True
if __name__ == "__main__":
restart_on_exit = True
while restart_on_exit:
restart_on_exit = my_app()
That way the code will loop, running my_app
over and over again, if the popup sets restart_on_exit
to True
before the loop repeats.