Version 9 of Embedded Toplevels

Updated 2011-06-03 12:47:36 by RLE

Tk has the ability to embed a toplevel inside another, or inside a frame. The -use and -container options are used for this, along with [winfo id]. For example:

 toplevel .top -container true
 toplevel .embed -use [winfo id .top]

or:

 frame .f -container true
 toplevel .embed -use [winfo id .f]

This can also work across processes on UNIX (and possibly Windows). The wish application also takes a -use option which works in the same way (the root "." window becomes embedded). On MacOS X, however, this embedding is only supported within a single process (so, for instance the -use option to wish will not work). Jim Ingham writes on the tcl-mac mailing list:

"So I talked with some folks who work on the MacOS X WindowServer, and they said that there is currently no way to get a window ID that will work across processes. So -use will only work in one process on OS X."

NEM.


An interesting question is: Can this mechanism allow a widget hierarchy created under toplevel a to be moved under a different toplevel? An example would be a complex app main window which includes a frame holding a text widget and a bunch of other controls where you want the ability to pull that frame into its own toplevel. If I make the frame a toplevel can I do it? RT

NEM I don't think you can change the -use option of a toplevel after creation. It would be neat to have frames which you could "tear-off" from an application into a separate window, but I can't immediately see how to do it. Problem is that you would (currently) have to destroy the toplevel, and then recreate it without the -use (or with a different id). This would destroy all the sub-widgets though, so doesn't gain anything on other methods.

... how does BLT do this in their 'tabnotebook1.tcl' demo?

NEM See TIP 125: Adding [wm toplevel] command: [L1 ]