Calling tcl from python and viceversa

C

Carlos P.

Hi!
I want to call tcl from python and python from tcl. The big picture is
that I´m writing an application GUI with tcl/tk and application logic
with python, so at least I want to call python events from the tk GUI.
I have read about _tkinter and tkapp.call although I couldn´t find any
detailed documentation. And, anyway, that seems to work in one
direction (python->tcl) but I don´t know how to make it work in the
other (tcl->python).
Thank you,
Carlos
 
G

Gerard Sookahet

Carlos said:
Hi!
I want to call tcl from python and python from tcl. The big picture is
that I´m writing an application GUI with tcl/tk and application logic
with python, so at least I want to call python events from the tk GUI.
I have read about _tkinter and tkapp.call although I couldn´t find any
detailed documentation. And, anyway, that seems to work in one
direction (python->tcl) but I don´t know how to make it work in the
other (tcl->python).
Thank you,
Carlos

Hello,

I have found an hint in the Tcl Wiki about Tclpython:

http://mini.net/tcl/5630

May be this will help you a little.

Gerard Sookahet
 
D

dan

funny -- first look at the board and it's right on subject.

I'm trying to write an app that does some cool stuff with sound
samples, using tkSnack. But I'm stuck on a simple question -- how do
I insert some of my own code into the tkInter mainloop? I need the
sequencer to run in the background while the UI is up.

Forgetting about snack for the moment, how do I run _any_
non-event-driven code while my Tk widgets are active? (for instance,
animation in one window while menus are still available). I can't
find any demos that show this sort of behavior.

All the Tk examples I've seen set up the widgets and run
root.mainloop(). I can't for the life of me figure out what code this
call invokes, but it won't return until a quit command or some such
action is initiated by the user. TCL docs say that Tk_mainloop calls
tcl_DoOneEvent() in a dead loop until a quit flag is set, or something
like that.

My best guess is that I'm supposed to set up another thread to do my
stuff, and send messages to the Tkinter thread that trigger Tk events,
or something like that. But the Tkinter docs are so sketchy I can't
really get a handle on how to do it. Any help or pointers would be
appreciated.

thanks in advance - stumped
 
C

Cameron Laird

funny -- first look at the board and it's right on subject.

I'm trying to write an app that does some cool stuff with sound
samples, using tkSnack. But I'm stuck on a simple question -- how do
I insert some of my own code into the tkInter mainloop? I need the
sequencer to run in the background while the UI is up.

Forgetting about snack for the moment, how do I run _any_
non-event-driven code while my Tk widgets are active? (for instance,
animation in one window while menus are still available). I can't
find any demos that show this sort of behavior.

All the Tk examples I've seen set up the widgets and run
root.mainloop(). I can't for the life of me figure out what code this
call invokes, but it won't return until a quit command or some such
action is initiated by the user. TCL docs say that Tk_mainloop calls
tcl_DoOneEvent() in a dead loop until a quit flag is set, or something
like that.

My best guess is that I'm supposed to set up another thread to do my
stuff, and send messages to the Tkinter thread that trigger Tk events,
or something like that. But the Tkinter docs are so sketchy I can't
really get a handle on how to do it. Any help or pointers would be
appreciated.
.
.
.
In Tcl-think, one just lives with the "dead loop". There
is no "non-event-driven code". Tcl-ers go about as far as
anyone with this model. "[A]nimation in one window while
menus are still available"? The conventional Tcl response
is, "make the animation event-driven". I know how unaes-
thetic that will seem to most readers; study <URL: http://
wiki.tcl.tk/GUIAlive > for its full, native expression.

Tcl has added thread support over the last few years--but
not in the standard distribution. I've never seen a Tkinter
over a threading Tcl; I don't know how well it works. Maybe
it's just what you're after.
 
J

Jeff Epler

You can convert your code so that it runs from callbacks
(after/after_idle), or so that it calls the Tk event handler at reasonable
intervals. The first approach means greatly changing your code (though
you may be able to abuse generator functions here), and the second
approach means that a few Tk things will interact badly with your fake
mainloop (tk_wait). Threading is another possibility, but it's
problematic with Tk because you must make sure all Tk calls happen in
only one thread (the main thread, I think; or maybe the thread that
created the Tk instance)

Jeff
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top