1

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)
codeforfood
  • 429
  • 9
  • 28
  • This is probably the same problem as was solved here: http://stackoverflow.com/questions/12043693/python-and-tkinter-aftermilliseconds-event-looping-indefinitely-never-enteri – ebarr Jul 12 '13 at 06:54

1 Answers1

2

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)
Noctis Skytower
  • 21,433
  • 16
  • 79
  • 117