I am writing an application using the tkinter module in Python. The section of code I am having trouble with is:
def sceneChange():
global num
num = num + 1
currentScene = scenes[num]
global label
label.destroy()
label = tk.Label(window, image = currentScene)
label.pack()
time1 = dt.datetime.utcnow().minute + dt.datetime.utcnow().second / 60
testTime = time1 + 4.44 / 60 # ~5 secs in the future
while dt.datetime.utcnow().minute + dt.datetime.utcnow().second / 60 < testTime:
pass
label.destroy()
num = num + 1
currentScene = scenes[num]
label = tk.Label(window, image = currentScene)
label.pack()
Which is used in:
b = tk.Button(label, text = "Start", command = sceneChange, height = 1, width = 10)
b.place(x = 440, y = 48)
The label.pack command before the while loop is not showing in my window. I am trying to make it display for 5 seconds then switch the image to something else. But, it isn't. All help would be appreciated. If I have done something wrong in the formatting of my question, please let me know so I can improve it :). The whole code is below:
import tkinter as tk
import datetime as dt
window = tk.Tk()
window.title("Game")
scenes = [tk.PhotoImage(file = "TitleScreen.gif"), tk.PhotoImage(file = "ControlsScreen.gif"), tk.PhotoImage(file = "game.gif")]
num = 0
currentScene = scenes[num]
label = tk.Label(window, image = currentScene)
def sceneChange():
global num
num = num + 1
currentScene = scenes[num]
global label
label.destroy()
label = tk.Label(window, image = currentScene)
label.pack()
time1 = dt.datetime.utcnow().minute + dt.datetime.utcnow().second / 60 # current time
testTime = time1 + 4.44 / 60 # ~5 secs in the future
while dt.datetime.utcnow().minute + dt.datetime.utcnow().second / 60 < testTime:
pass
label.destroy()
num = num + 1
currentScene = scenes[num]
label = tk.Label(window, image = currentScene)
label.pack()
label.pack()
b = tk.Button(label, text = "Start", command = sceneChange, height = 1, width = 10)
b.place(x = 440, y = 48)
b1 = tk.Button(label, text = "Quit", command = exit, height = 1, width = 10)
b1.place(x = 440, y = 78)
label.mainloop()