Oct-16-2024, 07:20 PM
Hi,
I want to create a memory game. I need the game to pause for a while. I understand that sleep stops the whole program running which is no good. I have tried after but cannot get another function to create a user entry box to run from it.
1. The screen will load with instructions that says click the start button to begin the game.
2. Clicking start loads a picture with a label for its name (and supposedly starts a 5 second timer)
3. The image is supposed to go away and in its place is supposed to a user entry box where you can enter the name of the image you just saw.
I can get the picture and label to load and using after go away after 5 seconds. Any functions i add to this don't trigger.
I have just tried to fun a function off after (see function 'iamtrying' and it will print the string but wont destroy the image or create the entry box.
The bus image is attached to post.
Any help would be greatly received.
Thanks in advance
I want to create a memory game. I need the game to pause for a while. I understand that sleep stops the whole program running which is no good. I have tried after but cannot get another function to create a user entry box to run from it.
1. The screen will load with instructions that says click the start button to begin the game.
2. Clicking start loads a picture with a label for its name (and supposedly starts a 5 second timer)
3. The image is supposed to go away and in its place is supposed to a user entry box where you can enter the name of the image you just saw.
I can get the picture and label to load and using after go away after 5 seconds. Any functions i add to this don't trigger.
I have just tried to fun a function off after (see function 'iamtrying' and it will print the string but wont destroy the image or create the entry box.
The bus image is attached to post.
Any help would be greatly received.
Thanks in advance
import tkinter as tk window = tk.Tk() window.title("Test Environment") window.geometry("450x700") window.configure(background="silver") score = 0 def iamtrying(): print("Hello") spot1.destroy spot1_label.destroy user_input=tk.Entry(window,width=50) user_input.place(x=85,y=600) def startgame(): global spot1 bus_image = tk.PhotoImage(file="bus.png") spot1 = tk.Label(window,image=bus_image) spot1.image = bus_image spot1.place(x=90,y=130) spot1.after(5000,iamtrying) global spot1_label spot1_label=tk.Label(window,text="CAT",fg="black",bg="gold",font=("Arial",14,"bold")) spot1_label.place(x=90,y=240) # spot1_label.after(10000,spot1_label.destroy) mylabel=tk.Label(window,text="click start, after 5 seconds images") mylabel.place(x=90,y=400) mylabe2=tk.Label(window,text="will disappear, name them in input box.") mylabe2.place(x=90,y=430) startbutt=tk.Button(window,text="START GAME",fg="black",bg="gold",width=15,font=("Arial",12,"bold"),command=startgame) startbutt.place(x=140,y=550) window.mainloop()