pythonttkinter在第二次运行时崩溃了自动化桌面

2024-10-03 19:26:44 发布

您现在位置:Python中文网/ 问答频道 /正文

代码在第一次运行时按预期运行,但如果我再次运行它,它会使自动化服务台崩溃。如果我在Python中运行它,就没有错误,我可以重复运行它。在

AD”是AutomationDesk变量,在AutomationDesk之外不工作。对于测试,我将该部分注释掉,只使用DEBUG而不是AD.DEBUG。在

Automation desk是dSpace的一个软件。在

from Tkinter import *
import Tkinter,tkFileDialog,tkMessageBox
from datetime import datetime


#print time 
now = datetime.now()
print "Test Start time is: "+'%s:%s:%s' % (now.hour, now.minute,now.second)

#hide the main window
root = Tk()
root.withdraw()

#Debugger option
debugYN = tkMessageBox.askyesno("Debug", "Would you like to debug?")

if debugYN == True:
    _AD_.DEBUG = 1
    print "Debugging enabled"
else:
    _AD_.DEBUG = 0

#File name selection
file = tkFileDialog.askopenfilename()

if file != None and debugYN == True:
    print file

_AD_.DFCxlsPath = file


if _AD_.DEBUG == 1:
    now = datetime.now()
    print "Select XLS & Debug Completed at "+'%s:%s:%s' % (now.hour, now.minute,now.second)

root = None
#root.destroy()

del file
del debugYN
#remove now here because no matter what we print the start time
del now

Tags: fromdebugimportdatetimeiftimetkinterroot
1条回答
网友
1楼 · 发布于 2024-10-03 19:26:44

我在AutomationDesk中尝试使用Tkinter时遇到了同样的问题,所以我联系了他们寻求支持。以下是他们的官方回应:

“我们不建议在AutomationDesk Exec块中使用Tkinter。相反,我们建议您使用内部“Dialogs”库,您可以从AutomationDesk的库浏览器访问该库。此外,Tkinter不是线程安全的。在

请查看您电脑上的以下文档: C: \Program Files(x86)\Common Files\dSPACE\HelpDesk 2014-A\打印\自动任务指南.pdf>;故障排除>;使用Tkinter

原因是Tkinter和Python2.7之间的交互中出现线程问题。互联网上也有其他关于这个问题的报道。e、 g.:http://bugs.python.org/issue11077

不幸的是,Dialogs库不是很强大,我很难找到合适的文档。在

相关问题 更多 >