codeforfood
codeforfood

Reputation: 439

Infinite loop in Tkinter?

I am having a problem running a loop that will auto update some stuff. (Like game money) It is supposed to add 100 dollars every 30 seconds. The Gui won't load, but the shell does not give me any errors. Thanks in advance!

def update():
    while True:
        money = money + 100
        label.set(str(money))
        time.sleep(30)

Upvotes: 1

Views: 1610

Answers (1)

Noctis Skytower
Noctis Skytower

Reputation: 22041

Try writing your function this way instead. You should be scheduling your code to run, not looping it.

def update(money=0, increase=100, repeat=30):
    money += increase
    label.set(money)
    label._master.after(repeat * 1000, update, money, increase, repeat)

Upvotes: 2

Related Questions