Reputation: 243
I am having a problem with Python's Tkinter module. When I try and make a canvas it won't appear until the shell is done printing. My code looks like this:
from tkinter import *
import time
tk = Tk()
canvas = Canvas(tk, width=500, height=500)
canvas.pack()
money = 500
canvas.create_text(100, 30, text="Money: " + str(money), font=('Impact', 25))
time.sleep(2)
print("Give Me A Chance To Load")
time.sleep(4)
buy = input("Will You Buy A Cow?")
if buy == "Yes":
money -= 50
if buy == "No":
money -= 999999999999999999999
This program is supposed to update the money live in the canvas. The thing is the canvas won't appear until you answer the input and the money is still at 500. What am I doing wrong?
Upvotes: 0
Views: 224
Reputation: 386382
You are calling time.sleep(...)
. Are you aware what that does? It causes your program -- your whole program -- to sleep. When it is sleeping it can't be doing other things such as drawing itself to the screen.
Also, a GUI (using just about any toolkit) can't be drawn until an event loop is running. It is the event loop responding to a "request to draw" event that causes a window to appear on the screen.
Tkinter isn't designed to work with input from the console. Attempting to do so will almost always yield disappointment.
Upvotes: 1