473,387 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Interaction between TclTk editor with Python code

ab
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.

Jul 19 '05 #1
1 1411
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-----

Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Helmut Jarausch | last post by:
Hi, has anybody managed to get IDEStudio running on Linux with Python 2.3b2+ (cvs) plus TclTk 8.4.3 + tix-8.1.4 ? After a minor correction to src/idledev/IDEStudio.py to set 'srcdir'...
2
by: stephenlee | last post by:
I want to develop a simple Python program to edit source code that is persisted in a database (memo fields). The code to be edited is iHTML and SQL and I want syntax colouring and good basic...
1
by: Grzegorz Dostatni | last post by:
Does anyone have tcltk 8.3 packages for cygwin? I spend the last 6 hours searching for them on the net. Could you please check your cygwin archive? Greg "Many a man may look respectable, and...
3
by: Chris Cioffi | last post by:
I started writing this list because I wanted to have definite points to base a comparison on and as the starting point of writing something myself. After looking around, I think it would be a...
36
by: ChinStrap | last post by:
When not using the interactive prompt, what are you using? I keep hearing everyone say Emacs, but I can't understand it at all. I keep trying to learn and understand why so many seem to like it...
1
by: Crutcher | last post by:
I've been playing with dictionary subtypes for custom environments, and I encountered a strange interaction between exec, dictionary subtypes, and global variables. I've attached a test program,...
56
by: Omar | last post by:
I'd love the perfect editor that would be: a) free b) enable me to drag and drop code snippets from a sort of browser into the code c) can run programs right from within d) can edit
3
by: mmm | last post by:
I am looking for advice on Python Editors and IDEs I have read other posts and threads on the subject and my two questions at this time are mainly about the IDLE-like F5-run facilities. While I...
0
by: Chris | last post by:
Hi, I'm trying to build Python on Windows using Visual Studio 2005. I have no trouble compiling tcl/tk 8.5, but when I subsequently build Python it doesn't find tcl/tk (I get a message about...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.