Juan M Juan M - 3 years ago 246
Python Question

Python Tkinter Crashes Automation Desk on second run

Code runs as intended on the first time through but if I go to run it again it crashes automation desk. If I run it from within Python there are no errors and I can run it repeatedly.

"AD." are AutomationDesk variables that do not work outside of automationdesk. for testing I comment that part out and just use DEBUG instead of AD.DEBUG.

Automation desk is a software by 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()

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

if debugYN == True:
_AD_.DEBUG = 1
print "Debugging enabled"
_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

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

Answer Source

I ran into the same issue when trying to use Tkinter in AutomationDesk, so I contacted them for support. Here is their official response:

"we do not recommend using Tkinter within an AutomationDesk Exec block. We instead recommend using the internal 'Dialogs' library which you can access from the Library Browser in AutomationDesk. Furthermore Tkinter is not thread-safe.

Please have a look into the following documentation on your PC: C:\Program Files (x86)\Common Files\dSPACE\HelpDesk 2014-A\Print\AutomationDeskGuide.pdf > Troubleshooting > Using Tkinter

The cause is a thread problem in the interaction between Tkinter and Python 2.7. There are other reports of this problem on the Internet. e.g.: http://bugs.python.org/issue11077"

Unfortunately, the Dialogs library is not very powerful and I've had difficulty finding good documentation for it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download