代码第一次按预期运行,但如果我再次运行它,它会导致自动化桌面崩溃。如果我从 Python 中运行它,就不会出现错误,并且可以重复运行它。
“公元。”是在 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
最佳答案
当我尝试在 AutomationDesk 中使用 Tkinter 时遇到了同样的问题,因此我联系了他们寻求支持。以下是他们的官方回应:
“我们不建议在 AutomationDesk Exec block 中使用 Tkinter。我们建议使用内部“对话框”库,您可以从 AutomationDesk 中的库浏览器访问该库。此外,Tkinter 不是线程安全的。
请在您的 PC 上查看以下文档: C:\Program Files (x86)\Common Files\dSPACE\HelpDesk 2014-A\Print\AutomationDeskGuide.pdf > 疑难解答 > 使用 Tkinter
原因是Tkinter和Python 2.7交互时出现线程问题。互联网上还有关于此问题的其他报告。例如:http://bugs.python.org/issue11077 ”
不幸的是,Dialogs 库不是很强大,我很难找到合适的文档。
关于Python Tkinter 在第二次运行时导致 Automation Desk 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34160021/