so I made a progress bar for my login page in my application in customtkinter and I wanted to stop the progress bar at 100 or 1 , basically at max
I tried a lot of method like using while loop etc but when I did the application crashes/hangs I don't know why , and I didn't find any specific function for this purpose I even watched tutorial but its not mentioned in any , I would really appreciate anyone's help ,
NOTE :- MY PROGRESS BAR IS INSIDE A FUNCTION THAT CREATE AND RUN THE PROGRESS BAR WHEN I PRESS THE LOGIN BUTTON AFTER INPUTTING THE USERNAME AND PASSWORD
EDIT: Im sorry i should have provided more info on it now , i dont know if i should provide all the gui code or not since its around 150 lines , this is not the complete code but just where problem is so i just want to make this progress bar stop at 100 or 1 or max , i also tried putting while loop in pbarl function which will keep on checking for the value of progress bar, but it crashes i dont want the solution of the crash much but the main issue is stoppin it at max, funtion pbarl is attached to button b3 or login button which when pressed call it and this function creates a progress bar the step start is defined there only , entrythemechange function disables the entries and button in the page as the login button is pressed
import customtkinter
from PIL import Image, ImageTk
import pyglet
root = customtkinter.CTk()
root.geometry("610x600")
root.resizable(False, False)
root.configure(fg_color="black")
def Pbarl():
plogin = customtkinter.CTkProgressBar(root,
orientation="horizontal", height=15, width=300,
fg_color="black",border_width=2, border_color="white",
progress_color="white", determinate_speed=0.2)
plogin.grid(row=4, column=1, pady=10)
plogin.step()
plogin.set(0)
plogin.start()
def EntryColorChange():
b3.configure(fg_color="white", text_color="black",
state="disabled")
e3.configure(text_color="black", fg_color="white",
state="disabled")
e4.configure(text_color="black", fg_color="white",
state="disabled")
b3 = customtkinter.CTkButton(root, text="Login",
text_color="white", fg_color="black", font=("Bold", 17),
height=32, width=150, border_width=1, corner_radius=20,
border_color="white", hover_color="white", command= lambda :
(Pbarl(), EntryColorChange()))
b3.grid(row=5, column=1, pady=50)
b4 = customtkinter.CTkButton(root, text="Dark",
text_color="white", fg_color="black", width=30, height=25,
border_width=1, border_color="white", corner_radius=20,
hover_color="white")
b4.grid(row=0, column=2)
img3 = customtkinter.CTkImage(Image.open("Username icon 2.JPG"),
size= (27, 27))
img4 = customtkinter.CTkImage(Image.open("Password icon 3.PNG"),
size= (27, 27))
l4 = customtkinter.CTkLabel(root, text="LOGIN", font=
("bold",40),
text_color="white")
l4.grid(row=0, column=1, padx=15, pady=30)
l5 = customtkinter.CTkLabel(root, text="", text_color="white",
image=img3)
l5.grid(row=1, column=0, padx=7)
l6 = customtkinter.CTkLabel(root, text="", text_color="white",
image=img4)
l6.grid(row=2, column=0)
l7 = customtkinter.CTkLabel(root, text="")
l7.grid(row=3, column=1)
e3 = customtkinter.CTkEntry(root, width=300, height=30,
corner_radius=20, placeholder_text=" Username",
placeholder_text_color="white", font=("Bold", 17),
fg_color="black", border_width=1, border_color="white")
e3.grid(row=1, column=1, pady=10, ipadx=100)
e4 = customtkinter.CTkEntry(root, width=300, height=30,
corner_radius=20, placeholder_text=" Password",
placeholder_text_color="white", font=("Bold", 17),
fg_color="black", border_width=1, border_color="white")
e4.grid(row=2, column=1, pady=10, ipadx=100)
root.mainloop()
It is hard to help you without knowing what you tried and what exactly you are trying to achieve. However, here is a sample of how you can do a kind of loop that does not block the mainloop. (I suppose you have used something like sleep()
in your loop which causes the mainloop to pause as well. This in turn freezes your GUI!)
from customtkinter import CTk, CTkButton, CTkProgressBar
class LoginProgress(CTk):
def __init__(self):
super().__init__()
CTkButton(self, text='Login', command=self.login).pack(pady=10)
# create a progressbar which fills up in 10 steps (by 0.1 each step)
self.prgrs = CTkProgressBar(self, width=200, determinate_speed=5)
self.prgrs.pack(pady=(0, 10), padx=5)
# set it to start at 0
self.prgrs.set(0)
def login(self):
if self.prgrs.get() < 0.9:
# add 0.1 to progress value as determined in determinate_speed
# you could also set a value using self.prgrs.set()
self.prgrs.step()
# recursive call of login after 0.1sec to mimic a loop that is non blocking
self.after(100, self.login)
else:
# finally set the Value to 1 to show a complete progressbar
self.prgrs.set(1)
if __name__ == '__main__':
app = LoginProgress()
app.mainloop()
If login
is actually doing something time consuming and you want to show the progress of that function you can sprinkle the .step()
or .set()
methodes into your actual code followed by an update()
call to force the mainloop to display the value change on the progressbar:
def actual_login(self):
self.prgrs.set(0.2) # manually set the value to resemble 20% completeness
self.update()
important_stuppf() # do something time consuming
self.prgrs.set(0.5) # set to 50%
self.update()
another_lengthy_task() # do something time consuming
self.prgrs.set(0.8) # set to 80%
self.update()
final_steps_of_function() # do something time consuming
self.prgrs.set(1) # set to complete
self.update()