Update continuously even you have button and button is clicked.
Just put config text and root.update() inside function def.
The progress bar:
Program:
from tkinter import *
import time
root=Tk()
a=Label(root,fg="blue")
a.pack()
a.config(text="processing 10%")
root.update()
time.sleep(1)
#program
a.config(text="processing 30%")
root.update()
time.sleep(1)
#program
a.config(text="processing 60%")
root.update()
time.sleep(1)
#program
a.config(text="processing 100%")
root.update()
time.sleep(1)
root.mainloop()
Python tkinter update label progress bar while button is clicked.
The progress bar(with button):
from tkinter import *
import time
root=Tk()
a=Label(root,fg="blue")
a.pack()
def run():
a.config(text="processing 10%")
root.update()
time.sleep(1)
#program
a.config(text="processing 30%")
root.update()
time.sleep(1)
#program
a.config(text="processing 60%")
root.update()
time.sleep(1)
#program
a.config(text="processing 100%")
root.update()
time.sleep(1)
b=Button(root,text="run",command=run)
b.pack()
root.mainloop()
No comments:
Post a Comment