0
from tkinter.ttk import *
import time
root= Tk()
root.title("THis is our other lessons")
root.geometry("600x400")
prog=Progressbar(orient=HORIZONTAL,length=100,mode='determinate')
def bar():
    for i in range(1,100,1):
        prog['value']=i
        root.update_idletasks()
        root.after(2000,root.destroy)
prog.pack()
butt=Button(text="Start",command= bar())
butt.pack()
root.mainloop()

I tried this method to run the progress bar but it did not worked with time.sleep, so I tried after method but the output directly reaches to end.

martineau
  • 119,623
  • 25
  • 170
  • 301
  • 1
    What do you mean "it did not work"? What happens when you run your code? What do you want it to do instead. – Code-Apprentice Apr 14 '22 at 18:03
  • 3
    To be clear, you want to destroy your root window 100 times after 100 different 2sec delays? Am I reading that right? Are you worried your root window is a zombie? – Silvio Mayolo Apr 14 '22 at 18:04

1 Answers1

0
butt=Button(text="Start",command= bar())

The problem is that you call bar() and take the return value as the button's command. This causes bar to execute immediately instead of when the user clicks the button. To fix this, remove the parentheses to make bar itself the command:

butt=Button(text="Start",command= bar)
Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268