'Trying to make game able to be restarted
I am making a typing test for a project using tkinter, and the last thing I need to do is to have it be able to restart when the user presses the restart button.
def test():
def checksen():
#stuff
def stopgame():
#stuff
#main test program stuff
while elapsed < max_time:
#config stuff
while checksen() == False:
#stuff
#stuff
#after game
correct_counter-=1#typed sentence after max time does not count
senframe.destroy()
endframe = tk.Frame(win, bg = norm)
endframe.place(relx=.5,rely=0.025, anchor='n')
endlabel=tk.Label(endframe, text = f'FINISH \n You typed {correct_counter} sentences in {max_time} seconds, \n which is about {round(correct_counter/max_time, 2)} sentences per second. \n Want to test again?', font = 14, bg = norm)
endlabel.pack()
restartbutton = tk.Button(endframe, text = 'RESTART', bd = 3, command = start)
restartbutton.pack()
endbutton=tk.Button(endframe, text = 'FINISH', bd = 3, command = stopgame)
endbutton.pack()
#stuff```
I'm trying to have it so the restart button calls on start function again, but when it's pressed, nothing happens. I'm new to programming and I'm trying to understand inner functions. Is there an easier way to make my program restart able?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
