В моей программе у меня есть графический интерфейс с индикатором выполнения. Значение индикатора выполнения является переменной другого скрипта, поэтому я создал функцию обновления, которая обновляет графический интерфейс, поэтому у меня есть движущийся индикатор выполнения.
def update(lblhowfar,bar,window,Zeitraum,auswahl,testprogress):# update function to refresh the progress bar and the percentage label
while rd.filtering_done==False:
Progress=int(rd.Zähler/rd.Nenner)
percent=Progress,"%","of","100","%"
if testprogress < Progress:
bar['value'] = Progress
testprogress=Progress
lblhowfar.config(text=percent)
window.update()
time.sleep(.1)
if rd.filtering_done:# when RelevanteDaten.py is done
while rd.appending:
time.sleep(.5)
continue
bar['value'] = 100
percent="100","%","of","100","%"
lblhowfar.config(text=percent)
lbl2=Label(window, text="Filtering done",font=("Helvetica Neue 55 Roman",15))
lbl2.pack()
window.update()
RelevanteDaten=rd.RelevanteDaten# Import important data from RelevanteDaten.py
Continue(RelevanteDaten,lbl2,lblhowfar,bar,window,Zeitraum,auswahl,)
else:
window.after(1,update(lblhowfar,bar,window,Zeitraum,auswahl,testprogress))
в графическом интерфейсе. Я хотел иметь кнопку, которая выключит программу, но когда я выполню кнопку, я получу сообщение об ошибке.
def Destroy(window,):#shuts down the program
plt.close(fig="all")
window.destroy()
sys.exit()
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\User\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1702, in __call__
return self.func(*args)
File "CheckTool.py", line 258, in <lambda>
button1 = Button(window, text="Use", command=lambda:button_generate(window,checkVariableForCheckBoxList,Zeitraum,),font=("Helvetica Neue 55 Roman",20))
File "CheckTool.py", line 290, in button_generate
get_selected_boxes(checkVariableForCheckBoxList,window,Zeitraum,)
File "CheckTool.py", line 299, in get_selected_boxes
create_progress_bar(Zeitraum,auswahl,)
File "CheckTool.py", line 446, in create_progress_bar
progressscreen.after(1,update(lblhowfar,bar,window,Zeitraum,auswahl,testprogress))
File "CheckTool.py", line 231, in update
window.update()
File "C:\User\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1174, in update
self.tk.call('update')
_tkinter.TclError: can't invoke "update" command: application has been destroyed
так что, очевидно, функция обновления все еще работает, хотя она должна останавливаться с sys.exit (). Правильно?
Уже спасибо за вашу помощь.
С уважением