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

  2. 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. Advertisements

  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
     
    dan, Jul 20, 2003
    #3
  4. .
    .
    .
    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, 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. Advertisements

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 (here). After that, you can post your question and our members will help you out.