1

I want to update the text of my label while my program is doing things in the function. Now I only get the updated text at the end of the function ("2"). But I want the label to be updated while the def is running so that I can see the "1" for example too.

from tkinter import *
from tkinter import ttk
import time


def execute():
    var1.set("1")
    time.sleep(2)
    var1.set("2")

root = Tk()
root.title("title")

var1 = StringVar()
lblstatus = ttk.Label(root, textvariable=var1)
lblstatus.grid(column=0, row=1)

btnload = ttk.Button(root, text="Execute", command=execute)
btnload.grid(column=0, row=0)

root.mainloop()
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437

0 Answers0