Skip to content Skip to sidebar Skip to footer

Incerasing Number By Every Second +1 In Tkinter Label

My problem is, increasing numbers in while loop by every second. I have found the solution in shell, but 'time.sleep()' function doesn't work on 'Tkinter'. Please help! import time

Solution 1:

root.after is the tkinter equivalent of time.sleep, except that time is milliseconds instead of seconds. There are multiple examples on SO to study.

import tkinter as tk
root = tk.Tk()

money = 100
label = tk.Label(root, text = str(money)+"$")
label.grid()

defcountup(money):
    money += 1
    label['text'] = str(money)+"$"if money < 300:
        root.after(100, countup, money)

root.after(100, countup, money)
root.mainloop()

Solution 2:

You wouldn't normally want to be doing a sleep like that in a GUI program, but try this:

while money < 300:
    money += 1
    time.sleep(1)
    root.update()

Post a Comment for "Incerasing Number By Every Second +1 In Tkinter Label"