user442920
user442920

Reputation: 847

python and TCL: how to run scripts that need a console

I am trying to run TCL scripts from Python. I have a third-party TCL package included in the TCL script (which I have to use) which makes calls to "console". Because of this, if I just run the following:

z = x.tk.eval('source C:/somePath/GetStatsFirst2.tcl')

I get the following error:

pydev debugger: starting
WARNING!!! Unable to add paths from Appinfo: Could not find AppInfo registry entry
WARNING!!! Unable to add paths from Appinfo: Could not find AppInfo registry entry
Traceback (most recent call last):
  File "C:\Users\lab\Documents\Public\eclipse\plugins\org.python.pydev_2.7.5.2013052819\pysrc\pydevd.py", line 1397, in <module>
    debugger.run(setup['file'], None, None)
  File "C:\Users\lab\Documents\Public\eclipse\plugins\org.python.pydev_2.7.5.2013052819\pysrc\pydevd.py", line 1090, in run
    pydev_imports.execfile(file, globals, locals) #execute the script
  File "C:\Users\lab\Documents\Public\workspace\Version 1\....\TC1.py", line 55, in <module>
    test()
  File "C:\Users\lab\Documents\Public\workspace\Version 1\....\TC1.py", line 42, in test
    z = x.tk.eval('source C:/Users/lab/Documents/Public/TCL/Scripts/GetStatsFirst2.tcl')
_tkinter.TclError: invalid command name "console"

This definitely has something to do with the package I am using and the problem may be unavoidable. Since there is no TK console that is opened (because I am using the TK inter class and eval), I get the feeling there is a way around this. It looks to me like the package I am importing requires the existence of a TK console. When run on the command line, or through subprocess.call, everything works, but in those cases a console is opened. I am pretty sure the package is actually looking for a console. Is there a way to create the console along with the Tk object?

Upvotes: 0

Views: 1288

Answers (1)

Johannes Kuhn
Johannes Kuhn

Reputation: 15163

Ahh, the console command.

The console command is only available

  • on Windows
  • only with wish
  • and only in the master interp.

I suggest that you use tkcon instead. You just need to find the tkcon.tcl file, source it before you source GetStatsFirst2.tcl and execute the following Tcl command:

interp alias {} console {} tkcon

This uses tkcon as console then.

Edit: You can execute that Tcl command with

x.tk.eval('interp alias {} console {} tkcon')

in Python.

Upvotes: 1

Related Questions