[Tkinter-discuss] Hooking into custom Tcl/Tk Widgets from Tkinter (vis)
Jeff Epler
jepler at unpythonic.net
Fri May 13 18:40:52 CEST 2005
[copied to tkinter-discuss for the benefit of others]
On Fri, May 13, 2005 at 09:15:44AM -0600, David King wrote:
> I still would like to hear from someone on how I'd invoke creation of my
> new custom widget and send it commands from python. The C++ code registers
> callbacks for both these sorts of things with the Tcl interpreter, so that
> they become available as _Tcl/Tk_ commands. But how can such commands be
> sent from python to Tkinter's Tcl/Tk interpreter?
By using the "call" method of the "tkapp" object, which is the .tk
attribute of each widget. Did you look at how widgets methods are
implemented?
def activate(self, index):
"""Activate item identified by INDEX."""
self.tk.call(self._w, 'activate', index)
This is turned into a tcl command like
.135964900 activate 1
You can call any Tk command you like in this way.
> At the risk of putting too many questions in one email, I'll also mention
> the other main problem I'm wrestling with. I need to understand the
> 'interactive' aspects of Tkinter--i.e., how _both_ the Tkinter gui(s) and
> python's sommand-line interpreter can remain 'live' at the same time, each
> responding to its own type of input.
I don't know exactly how all this works. I don't write threaded code,
so I don't know much about the pitfalls of it on various systems. On
Unix, you have _tkinter.createfilehandler() so that you can turn your
non-gui I/O into something that works via callbacks. Or you can arrange
for "update" to be called periodically from a non-Tk event loop, never
calling the Tk mainloop function. Finally, you could do something
operating-system specific, such as (on Unix) finding the file
numbers for both the X server connection and stdin, then feeding them
both to select.
Finally, if you want to use the threading approach, I think it's safe if
you use the GUI only in the main thread---including things like getting
and setting the values of Tkinter.Variables---and do anything else you
like in the other threads. But as I said, I don't generally write
threaded programs.
Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20050513/5433d797/attachment.pgp
More information about the Tkinter-discuss
mailing list