Python, Tkinter and Tcl (newbie alert)

Michael P. Reilly arcege at shore.net
Thu May 20 16:10:21 EDT 1999


John Huber <r42922 at email.sps.mot.com> wrote:
: I've got a couple of questions that will probably expose my ignorace (sorry in advance).

: I have a Tcl script (it doesn't use Tk) that runs some test equipmemt (via
: GPIB) and sucks in ascii data. The main reason I wrote it in Tcl is that is
: what had the GPIB library. Sometime later (recently), I wrote a script for
: manipulating some of the acquired data. For no particular reason [*] I chose
: to do it in Python. Both things work well, but now, for various reasons, I'd
: like to combine them into a single package (without porting one script to the
: other language), with a few graphical elements. Tk (Tkinter) seems like a
: logical way to do this. 

: I could just run the Tcl script using os.system() (I think), but seeing how
: Tkinter is so closely related to Tcl, I was wondering:):

: When Python uses Tkinter, is it really running a Tcl shell in some form? and
: if so, is it possible to execute Tcl code in this shell, something akin to
: importing modules?

Yes, exactly correct.  Tkinter is running a C level Tcl/Tk interpreter;
unfortunately, it is in the Tk world, so running a Python script and
attempting to access the Tcl interpreter with Tk wouldn't work well.

But much of the basic functionality is there that you would need.
  from Tkinter import Tk
  root_window = Tk()

  tcl_interp = root_window.tk

  tcl.interp.evalfile('laugh.tcl')
  tcl_version = tcl.interp.getvar('tcl_version')
  tcl_interp.setvar('a', 20)
  print tcl_interp.call('set', 'a')

It shouldn't be hard to make a small Tcl interpreter object based on
the one Tkinter uses.

  -Arcege





More information about the Python-list mailing list