[Tutor] How to put an event into the Tcl/Tk event queue?

Alan Gauld alan.gauld at btinternet.com
Sun Aug 26 18:04:38 CEST 2007

"Daniel Knierim" <tknierim at mail.ieway.com> wrote

> I'd like to simulate user input to TkInter applications from
> another Python script, by inserting events in the Tcl event queue.

There are two scenarios where I'd expect that to be needed:
1) To roboticise an existing app, particularly if you don;t have 
source code access.
2) testing a GUI.

Other than that it's usually easier to go in at the level below the 
GUI and
call the underlying commands directly. Is that a possibility here?

> Tcl/Tk has a couple functions for this (Tk_QueueWindowEvent
> and Tcl_QueueEvent).

These were new to me and indeed don't appear in either of
my Tcl refrence books (Ousterhout and O'Reilly Nutshell)
Are they recent additions?

> Is there a Python interface for either of those?  I can't find 
> any...

Neither can I.

> My second choice would be to use Tcl_CreateEventSource,
> but I don't see a Python interface for that, either.

Nope, me neither. No references in my books and no
Python/Tkinter equivalents. In fact my Tcl prompt doesn't
recognise any of the 3 commands you cite. Are these
actuially Tcl/Tk interpreter commands or C interface
functions? Only interpreter commands are reproduced
in Tkinter.

> I'd rather not work through the actual GUI interface if I can avoid 
> it.

Why do you need to work through the GUI events?
Normally the GUI is there to connect humans to the back end code.
If an app needs access to the back end code it can usually call the
functions directly using more conventional IPC mechanisms.

Thee are a couple of higher level methods that might be of use?

send(app, cmd, *args)

event_generate(sequence, option=...)

Dunno if they will help.

Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list