1

I want to create a progress bar where when you press a button to call another function, the progress bar runs, then ends when that function is done. So press a button, progress bar goes for however long it takes that function to finish, then stops when that function has completed. This is what I have come up with so far, but I'm not sure why the progress bar doesn't start. Any advice or pointers would be much appreciated. Thanks!

import time
import threading
from tkinter import *
from tkinter import ttk
from random import randint

root = Tk()

root.geometry("250x250")

label = Label(root, text="")
label.pack(pady=20)

progress_bar = ttk.Progressbar(root, orient = HORIZONTAL, length = 100, mode = "indeterminate")
progress_bar.pack(pady = 50)

def start_time():
    time.sleep(5)
    label.config(text="Done")

thread_1 = threading.Thread(target=start_time)

my_button1 = Button(root, text="Start", command=thread_1.start)
my_button1.pack(pady=20)

while thread_1.is_alive == False:
    progress_bar.start(10)
else:
    progress_bar.stop


root.mainloop()

0 Answers0