Calling tcl from python and viceversa

Discussion in 'Python' started by Carlos P., Jul 19, 2003.

  1. Carlos P.

    Carlos P. Guest

    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
     
    Carlos P., Jul 19, 2003
    #1
    1. Advertising

  2. Carlos P. wrote:

    > 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
     
    Gerard Sookahet, Jul 19, 2003
    #2
    1. Advertising

  3. Carlos P.

    dan Guest

    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


    (Carlos P.) wrote in message news:<>...
    > 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
     
    dan, Jul 20, 2003
    #3
  4. In article <>,
    dan <> wrote:
    >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.
    --

    Cameron Laird <>
    Business: http://www.Phaseit.net
    Personal: http://phaseit.net/claird/home.html
     
    Cameron Laird, Jul 20, 2003
    #4
  5. Carlos P.

    Jeff Epler Guest

    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
     
    Jeff Epler, Jul 20, 2003
    #5
    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. Michael Schlenker
    Replies:
    4
    Views:
    1,673
    Jonathan Ellis
    Jul 9, 2005
  2. NM
    Replies:
    2
    Views:
    423
  3. Bhan
    Replies:
    10
    Views:
    714
    mlimber
    Sep 19, 2005
  4. tarlino
    Replies:
    0
    Views:
    292
    tarlino
    Mar 4, 2008
  5. Mumia W.

    Inline::Tcl vs. Inline::Tcl

    Mumia W., Aug 23, 2006, in forum: Perl Misc
    Replies:
    0
    Views:
    155
    Mumia W.
    Aug 23, 2006
Loading...

Share This Page