Version 21 of How to embed a non-Tk GUI into a Tk frame

Updated 2008-04-08 11:04:51 by tonytraductor

Purpose: to collect tips, suggestions, questions, and examples where developers have written tcl/tk code that wraps around an existing GUI window.

In particular, I'm interested in hearing people talk about doing this under the X Window System.

Has anyone an example, for instance, of embedding perhaps an xterm inside a tcl/tk frame?

AMG: Try this.

 exec xterm -into [scan [winfo id .] %x] &

But Tk has no knowledge of the xterm stowing away in its toplevel, and the xterm doesn't seem to know much about its parent window, so there's no geometry propagation whatsoever. Hey, what do you expect from one line of code!? ;^)

tonytraductor I've noted that, using the above technique, closing the parent windows makes the xterm disappear, but does not kill the xterm process, which must then be killed manually (using a sysmon or with a new terminal on the command line), unless, of course, one includes something more like set ::pid exec xterm -into ... exec kill -9 $::pid; exit I'm interested in learning how to embed other applications, such as an mplayer video screen. Mplayer -into does not work.

sg man mplayer. Seek for a keyword... Okay, embed, for example. Aha, there is -wid option in MP's options set. I'm trying a line...

 exec /usr/bin/mplayer -wid [expr [winfo id .f]] /usr/share/example-content/Experience\ ubuntu.ogg &

It quite works for me. Try it.

tonytraductor It was precisely the winfo id .f part that I needed (I'd read the mplayer documentation and seen -wid, but didn't know how to give if the relevant info, even after googling wid, window id, etc.). Thanks!


LV From a recent discussion on comp.lang.tcl regarding a request for code so that an application could let the user use a personal preference of editor.

 package require Tk
 frame .f -container yes
 pack .f -fill both -expand yes
 # Solaris users should note that neither /usr/openwin/bin/xterm or
 #   /opt/sfw/bin/xterm apparently are new enough to have the -into.
 #   so you are resigned to do without or to get a newer version of xterm
 exec xterm -into [ expr [winfo id .f ]] -e $env(EDITOR) & 

Why? Well, perhaps, for example, to have an application to which one could easily add buttons for generating key sequences or command strings, etc.


[Larry, if no one else helps, and I don't otherwise make time for this, e-mail CL. I think I know what you're after.]

Thanks. A developer here is wanting to use something like this and then to set transient wm hints via tk, to get certain behavior characteristics to take place.


See BLT's 'container' command. From the man page...

The container widget lets you embed an X11 window from a foreign application into your Tk application. The foreign window is reparented inside of the widget. You can then place and arrange the container just as you would any Tk widget.

- Marty Backe -- 24 Nov 2004


See the page about the TkXext extension at http://wiki.tcl.tk/2116 It's a compiled Tcl/Tk extension. I think it only works on X11 on Unix/Linux. But you can embed non-Tcl/Tk windows inside a Tk frame with it. I used it in a project on Slackware 7.2 Linux with Tcl/Tk 8.4 and it worked well.


LV Has anyone used the frame -container option to do this sort of thing?


Googie Pretty easy example is to embed mplayer into Tk frame or toplevel window. Mplayer has -wid option, which orders mplayer to embed in X11 window with given ident. We can resolve ident of our toplevel or frame by wm.

tonytraductor How does one determine the wid parameter to use?


Rildo Pragana - For a multimedia window, you may even crop and pan its shown media, with Tk'k place geometry manager, see Crop multimedia with tk's place.


Category GUI