python - python 脚本不会随着 sys.exit() 停止
问题描述
在我的程序中,我有一个带有进度条的 GUI。进度条的值是另一个脚本的变量,所以我创建了一个刷新 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() 停止。正确的?
已经感谢您的帮助。
亲切的问候
解决方案
推荐阅读
- mongodb-query - 如何在mongoDB中获取数组的最后N个元素?
- delphi - 如何使用 MSXML6 解析 DTD 节点结构
- swift - 在无关的开关盒中放置什么?
- javascript - 异步和等待不工作g
- reactjs - npm start 和 npm run 构建失败并出现 npm ERR!代码生命周期
- tensorflow - 在张量流对象检测中找到最佳学习率
- javascript - Javascript 等效于 R 的 dataVector[indicesVector]?
- acumatica - 需要帮助携带销售订单用户字段以创建采购订单屏幕
- r - 将日期从 2019-07-04 14:01 +0000 转换为 MM/dd/yyyy 格式
- batch-file - 如何通过 bat 文件执行 cmd 命令?