Reputation: 88
When I run the program, it first waits until I enter input, then it will play the sound, then it shows the window with my image. Why is it doing this out of order?
from tkinter import *
import winsound
main = Tk()
main.state('zoomed')
main.geometry("1366x768")
# Displays a gif.
def show():
dollar_canvas = Canvas(width=50, height=50, bg='lightgrey', highlightthickness=0)
dollar_canvas.place(x=850, y=25)
my_gif = PhotoImage(file='Dollar50x50.gif')
dollar_canvas.image = my_gif
dollar_canvas.create_image(0, 0, image=my_gif, anchor=NW)
# Accepts an input, such as enter.
def getinput():
a = input()
# Plays a ring sound.
def play():
winsound.PlaySound('money', winsound.SND_ALIAS)
show()
getinput()
play()
mainloop()
Upvotes: 0
Views: 1004
Reputation: 385910
They aren't running out of order. Throw in a few print statements to see the order they are executing in. The problem is that until the event loop (mainloop
) runs, tkinter doesn't have an opportunity to update the display. In your code mainloop
won't run until the other functions finish.
To force the display to update you can call root.update_idletasks()
.
Upvotes: 1