import time from tkinter import * tk = Tk() canvas = Canvas(tk, width=400, height=400) canvas.pack() rectangle = canvas.create_rectangle(350, 10, 375, 200, fill="blue") canvas.itemconfig(rectangle, outline="black") triangle = canvas.create_polygon(10, 10, 10, 60, 50, 35, fill="red") canvas.itemconfig(triangle, outline="black") def startgame(): while 1: for x in range(0, 60): canvas.move(rectangle, 0, 4) tk.update() time.sleep(0.04) for x in range(0, 60): canvas.move(rectangle, 0, -4) tk.update() time.sleep(0.04) time.sleep(20) canvas.create_text(200, 200, text="GAME OVER", font=('Times', 30), fill="red") canvas.delete(rectangle) canvas.delete(triangle) btn = Button(tk, text="Start Game", command=startgame) btn.pack()Currently this is the beginning of my simple game. When I try to create the loop it stops afterwards(moving rectangle) and prints "Game Over" after a few seconds. I need it to continue and then print game over after the specified time. Thank you very much for the help.
[Tkinter] Loop help in game
Possibly Related Threads… | |||||
Thread | Author | Replies | Views | Last Post | |
How to put my game loop into a function? | temlotresid6 | 7 | 1,843 |
Oct-29-2024, 05:17 AM Last Post: menator01 |
|
If 2nd input in the game is correct, replace with 1st input and loop the game | tylerdurdane | 11 | 6,478 |
Jul-17-2022, 04:55 AM Last Post: deanhystad |
|
[PyGame] Problem With Entering Game Loop | ElevenDecember | 3 | 4,014 |
Jan-19-2020, 08:25 AM Last Post: michael1789 |
Users browsing this thread: 1 Guest(s)