Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Does anyone know how to restart the program like, for example, when a player reaches 5 points, after the text "Player a Wins" it will give a certain amount of time delay and then directly restart the game from 0 0. i created the score thingy but got stuck on restarting the program once it reaches 5 points?

I have imported turtle as game in the beginning.

if (scoreboard_a > 4):
    win.write("Player A WINS!", font=textfont2)
    game.reset()
elif (scoreboard_b > 4):
    win.write("Player B WINS!", font=textfont2)
    game.reset()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
264 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can restart the whole program like this:

import os
import sys
import time
time.sleep(2)
os.execl(sys.executable, sys.executable, *sys.argv)

Or, you can reset the score(s) and other elements, like:

time.sleep(2)
# reset variables 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...