python脚本不会因sys.exit()

时间:2019-03-27 09:18:10

标签: python python-3.x tkinter

在我的程序中,我有一个带有进度条的GUI。 progressbar的值是其他脚本的变量,因此我创建了一个更新功能来刷新GUI,因此我有一个移动的进度条。

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))

在GUI上,我想要一个可以关闭程序的按钮,但是当我执行该按钮时,会收到错误消息。

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()停止。对吧?

已经感谢您的帮助。

亲切的问候

0 个答案:

没有答案