TomSchimansky / CustomTkinter

A modern and customizable python UI-library based on Tkinter
MIT License
11.51k stars 1.08k forks source link

customtkinter.CTkLabel display error #871

Open orztrickster opened 1 year ago

orztrickster commented 1 year ago

I use customtkinter.CTkLabel as the percentage display next to the ProgressBar But when refresh with app.after(2000,aa) function It will be found that there is a high probability that the number displayed by customtkinter.CTkLabel will disappear (switching the window will increase the probability of occurrence), and it will run to the upper left corner of the screen and will display: [Exception in Tkinter callback]

2022-12-16 (17) `

def aa():
    global N

    if(Queue_save_E_coli_file.empty()==False):   #儲存參數檔案
        save_E_coli_file=Queue_save_E_coli_file.get()
        progressbar_save_E_coli_file.set(save_E_coli_file)
        logo_label = customtkinter.CTkLabel(progressbar_label_save_E_coli_file, text=str(math.floor(save_E_coli_file*100))+"%", font=customtkinter.CTkFont(family="Microsoft JhengHei",size=10, weight="bold"))
        logo_label.grid(row=0, column=2, padx=5, pady=0,sticky=tkinter.E, ipadx=5)
        app.update()
        app.after(2000,aa)

    if(Queue_output_video_schedule.empty()==False):   #影片壓制進度
        output_video_schedule=Queue_output_video_schedule.get()
        progressbar_output_video.set(output_video_schedule)
        logo_label = customtkinter.CTkLabel(progressbar_label_output_video, text=str(math.floor(output_video_schedule*100))+"%", font=customtkinter.CTkFont(family="Microsoft JhengHei",size=10, weight="bold"))
        logo_label.grid(row=0, column=2, padx=5, pady=0,sticky=tkinter.E, ipadx=5)
        app.update()
        app.after(2000,aa)

    if(Queue_create_ball_schedule.empty()==False):   #場地建立進度進度
        create_ball_schedule=Queue_create_ball_schedule.get()
        progressbar_create_ball.set(create_ball_schedule/100)
        logo_label = customtkinter.CTkLabel(progressbar_label_create_ball, text=str(math.floor(create_ball_schedule))+"%", font=customtkinter.CTkFont(family="Microsoft JhengHei",size=10, weight="bold"))
        logo_label.grid(row=0, column=2, padx=5, pady=0,sticky=tkinter.E, ipadx=5)
        app.update()
        app.after(10,aa)

    nnn=0
    if(Queue_E_coli_sports_schedule.empty()==False):
        while (Queue_E_coli_sports_schedule.empty()==False and nnn<=used_core*50):
            nnn+=1
            E_coli_sports_schedule=Queue_E_coli_sports_schedule.get()

            N[E_coli_sports_schedule[0]]=E_coli_sports_schedule[1]

        for i in range(used_core):
            progressbar[i].set(N[i])

            logo_label = customtkinter.CTkLabel(progressbar_label[i], text=str(int(math.floor(N[i]*100)))+"%", font=customtkinter.CTkFont(family="Microsoft JhengHei",size=10, weight="bold"))
            logo_label.grid(row=0, column=2, padx=5, pady=0,sticky=tkinter.E, ipadx=5)

            app.update()

        app.after(500,aa)

    app.after(500,aa)

app.after(500,aa)

app.mainloop()`
orztrickster commented 1 year ago

I solved this problem This is because too many nested evaluations So the app.after(10,aa) function should not be placed in the if function.