470,826 Members | 1,941 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,826 developers. It's quick & easy.

Interaction between TclTk editor with Python code


I have an editor(front end) that is written in Tcl/Tk.
It has a menu bar, menu buttons, edit boxes, listboxes & comboboxes.
I am invoking this editor from an application that is written in
all the necessary processing is done in Python and displaying is done
by the Tcl/Tk code.

Now if I make some changes in the GUI, say I change some value in the
editbox or set some value in the list box and click on save in the GUI,
how can I read the changed values from Python?
I mean, how can I get the value changed in the GUI into some Python


Jul 19 '05 #1
1 1326
One way to get a handle on some Tcl variables from Python is to create
Tkinter.Variable instances with the names of the existing Tcl variables
(normally, the variable names are chosen arbitrarily). Once you've done
this, you can do things like add variable traces (the trace_variable
method) on the Python side. One thing to be aware of is that the Python
object's __del__ will unset the variable on the Tcl side. Also, this
code sets an initial value for the variable which may or may not be
appropriate in your application.

The code below was ripped from a larger application, so it may or may
not work without modification.


# This code is in the public domain
from Tkinter import *
def makevar(master, name, klass, *default):
self = newinstance(klass)
self._master = master
self._tk = master.tk
self._name = name
if default:
return self

def makebool(master, name, *default):
return makevar(master, name, Tkinter.BooleanVar, *default)
def makeint(master, name, *default):
return makevar(master, name, Tkinter.IntVar, *default)
def makefloat(master, name, *default):
return makevar(master, name, Tkinter.DoubleVar, *default)
def makestring(master, name, *default):
return makevar(master, name, Tkinter.StringVar, *default)

Version: GnuPG v1.2.6 (GNU/Linux)


Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Helmut Jarausch | last post: by
2 posts views Thread by stephenlee | last post: by
1 post views Thread by Grzegorz Dostatni | last post: by
3 posts views Thread by Chris Cioffi | last post: by
36 posts views Thread by ChinStrap | last post: by
56 posts views Thread by Omar | last post: by
reply views Thread by Chris | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.