Interaction between TclTk editor with Python code

Discussion in 'Python' started by ab, May 17, 2005.

  1. ab

    ab Guest

    Hi,

    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
    Python.
    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
    variable?

    Thanks,
    Ab.
     
    ab, May 17, 2005
    #1
    1. Advertising

  2. ab

    Jeff Epler Guest

    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.

    Jeff

    # 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:
    self.set(default[0])
    else:
    self.set(self._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)

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.6 (GNU/Linux)

    iD8DBQFCidvgJd01MZaTXX0RAn1gAJ9xhcjNEG/L79jYQUQQIGVPAQW16gCfUNeS
    vbV4CmyXWgzLgs/bH3upYkU=
    =WBcH
    -----END PGP SIGNATURE-----
     
    Jeff Epler, May 17, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Helmut Jarausch
    Replies:
    0
    Views:
    454
    Helmut Jarausch
    Jul 17, 2003
  2. Grzegorz Dostatni

    cygwin tcltk 8.3

    Grzegorz Dostatni, Nov 29, 2003, in forum: Python
    Replies:
    1
    Views:
    374
    Jason Tishler
    Dec 2, 2003
  3. Chris
    Replies:
    0
    Views:
    273
    Chris
    Sep 11, 2008
  4. Mike
    Replies:
    0
    Views:
    104
  5. Gene Heskett

    Re: tcltk, python, xml, gtk problems

    Gene Heskett, Nov 19, 2013, in forum: Python
    Replies:
    0
    Views:
    116
    Gene Heskett
    Nov 19, 2013
Loading...

Share This Page