Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to embed toplevel in to frame on linux

249 views
Skip to first unread message

Madan

unread,
Jun 11, 2013, 11:00:53 PM6/11/13
to
Tk developers,

i would like to embed toplevel in to frame (frame inside main window).
dock/undock embedded toplevel from frame or in to frame,

using -use option on toplevel, the toplevel can be embedded in to frames.

this works fine on Window but fails on Linux.
error message is "-use option can't be configured after creation of widget"

e.g:
# main window
toplevel .top;
pack [frame .top.fr -container true]

# this linw will dock .subWindow in to .top.fr
toplevel .subWindow -use [winfo id .top.fr]

# to undock the .subWindow
.subWindow configure -use {}


now the problem is this works fine only on Windows. it throws error on Linux saying "-use option can't be configured after creation of widget"

please help me how to get dock/undock on feature on Linux. your help is really appreciated.

Thanks,
Madan

Christian Gollwitzer

unread,
Jun 12, 2013, 1:33:47 AM6/12/13
to
Hi Madan,

Am 12.06.13 05:00, schrieb Madan:
> i would like to embed toplevel in to frame (frame inside main window).
> dock/undock embedded toplevel from frame or in to frame,
>
> using -use option on toplevel, the toplevel can be embedded in to frames.
>
> this works fine on Window but fails on Linux.

This was the old-fashioned way. These days we have a special mechanism
for that: wm forget& wm manage, which transforms toplevels into frames
you can pack/grid and vice versa. Chcek toolbar.tcl in the Tk demos for
an example.

Christian

Madan

unread,
Jun 12, 2013, 11:58:14 PM6/12/13
to
> This was the old-fashioned way. These days we have a special mechanism
>
> for that: wm forget& wm manage, which transforms toplevels into frames
>
> you can pack/grid and vice versa. Chcek toolbar.tcl in the Tk demos for
>
> an example.
>
>
>
> Christian


Thank you Christian for your reply.

my use case way beyond this. i am trying to dock/undock notbook tabs from one notebook to other notebook.

e.g:
toplevel .top
ttk::notebook .top.nb1
.top.nb1 add [frame .top.nb1.tab1 -container true]
.top.nb1 add [frame .top.nb1.tab2 -container true]
# now i would like to embed toplevels in to the tab1 frame
toplevel .tab1 -use [winfo id .top.nb1.tab1]
toplevel .tab2 -use [winfo id .top.nb1.tab2]

#notebook2
ttk::notebook .top.nb2
.top.nb2 add [frame .top.nb2.tab1 -container true]
.top.nb2 add [frame .top.nb2.tab2 -container true]
# now i would like to embed toplevels in to the tab frames
toplevel .tab3 -use [winfo id .top.nb2.tab1]
toplevel .tab4 -use [winfo id .top.nb2.tab2]

# now i can move the toplevels between the tabs by using - use options
for e.g. to move .tab1 to notebook2 i simply create new tab in note book and embed the toplevel in to it.
.top.nb2 add [frame .top.nb2.tab3 -container true]
.tab1 configure -use [winfo id .top.nb2.tab3]

by doing this we can dock/undock the notebok tab contents between the notebooks without recreating the contents.

this works fine on Windows. on Linux -use options ca't be modified after creation.

Is there any alternate/better solution for this?

Thanks,
Madan

hae

unread,
Jun 13, 2013, 1:39:25 AM6/13/13
to
Hi Madan,

I think this is interesting for you http://wiki.tcl.tk/21846

Regards,

Rüdiger

Christian Gollwitzer

unread,
Jun 13, 2013, 2:59:56 AM6/13/13
to
Am 13.06.13 05:58, schrieb Madan:
>
> Thank you Christian for your reply.
>
> my use case way beyond this. i am trying to dock/undock notbook tabs from one notebook to other notebook.

I do not see a problem here. The "wm" mechanism basically converts
frames to toplevels and vice versa. So, for instance, if you have a
toplevel .content1, which you want to dock to notebook .note1, you can do

wm forget .content1
.note1 add .content1

and to undo

.note1 forget .content1
wm manage .content1

To me, this is a lot clearer than the frame/-use solution.


Christian

Madan

unread,
Jun 17, 2013, 1:24:18 AM6/17/13
to

> toplevel .content1, which you want to dock to notebook .note1, you can do
>
>
>
> wm forget .content1
>
> .note1 add .content1

Thank you Christian for your kind reply!

The problem is ttk::notebook does not add any frames if the frame/toplevel is not children of same toplevel meaning that for instance

toplevel .top
ttk::notbook .top.nb
toplevel .tab1
wm forget .tab1
.top.nb add .tab1
# will throw an error saying "can't add .tab1 as slave of .top.nb"

It works fine if the .tab1 is a children of .top meaning both notebook and the tab (toplevel) should be children of same toplevel.

Tab must be .top.tab1 then it works fine. this will not work if the notebooks are in two different toplevels then moving tabs between notebooks can't happen.

Thanks,
Madan

Madan

unread,
Jul 17, 2013, 9:55:01 AM7/17/13
to

any body has answer for this?

thanks,
Madan

tomás zerolo

unread,
Jul 17, 2013, 3:29:19 PM7/17/13
to
Madan <tmada...@gmail.com> writes:

> any body has answer for this?

I don't understand your question exactly: a toplevel is, by definition,
an "outermost" widget of the application. Outside it there is only the
window manager.

Perhaps you want to embed the frame in the toplevel, like this?

tomas@rasputin:~$ wish
% toplevel .t
.t
% pack [labelframe .t.f -text "I am a frame" -borderwidth 3]
% pack [entry .t.f.e]

(I'm using a labelframe here because it's more "visible").

Does that look a bit like what you are trying to achieve?

Regards
-- tomás

Christian Gollwitzer

unread,
Jul 17, 2013, 4:27:08 PM7/17/13
to
Am 17.07.13 21:29, schrieb tomás zerolo:
> Madan <tmada...@gmail.com> writes:
>
>> any body has answer for this?
>
> I don't understand your question exactly: a toplevel is, by definition,
> an "outermost" widget of the application. Outside it there is only the
> window manager.
>
> Perhaps you want to embed the frame in the toplevel, like this?
>
> tomas@rasputin:~$ wish
> % toplevel .t
> .t
> % pack [labelframe .t.f -text "I am a frame" -borderwidth 3]
> % pack [entry .t.f.e]
>

I think what he wants to do, is transfer a frame with all of it's
contents from one toplevel to another. Now that we have wm manage etc. ,
this would be an easy task:

toplevel .t1
toplevel .t2

# make a frame in .t1
frame .t1.f
pack .t1.f

# undock the frame into a free window
pack forget .t1.f
wm manage .t1.f

# make a frame in .t2
wm forget .t1.f
pack .t1.f -in .t2 ;# error

I think this is an arbitrary limitation of Tk, since the wm manage stuff
shows, that the frame *can* be moved out of .t1, but it is impossible to
pack it into .t2

Christian

Madan

unread,
Jul 17, 2013, 10:21:36 PM7/17/13
to
you can do these by using -container and -use option on toplevel/frame. this works fine on windows.

toplevel .t1 -container true
toplevel .t2 -container true

# make a frame in .t1
frame .t1.f -use [winfo id .t1]

# undock the frame into a free window
.t1.f configure -use "";

# dock the frame in to different toplevle
.t1.f configure -use [winfo id .t2]

this works fine on windowsbut on linux it says "-use" options on frame or toplevel cant be configured during runtime.

http://www.tcl.tk/cgi-bin/tct/tip
TIP #125: Converting between Frame and Toplevel Windows (implemented for 8.5) says that this works fine on both windows and Linux.

Thanks,
Madan

hae

unread,
Jul 18, 2013, 1:56:18 AM7/18/13
to
I have another guess. There is another application that has a toplevel (written in C with any toolkit, may qt). Now he wants to take this toplevel into a frame of his TclTk-application.

Somewhere I read that this should be possible. But I don't know where I read it.

Rüdiger

Madan

unread,
Jul 18, 2013, 12:23:56 PM7/18/13
to

tomás zerolo

unread,
Jul 20, 2013, 3:51:36 AM7/20/13
to
Madan <tmada...@gmail.com> writes:

> e.g:

[...]

> by doing this we can dock/undock the notebok tab contents between the notebooks without recreating the contents.
>
> this works fine on Windows. on Linux -use options ca't be modified after creation.

Ah, I see -- thanks for the clarification.

> Is there any alternate/better solution for this?

I fear you'll have to (re)create the window, as things stand now. I'd be
tempted to dive into the source (to understand the why of this
limitation), but I'm a bit pressed on time now, so sorry :-(

Regards
-- tomás
0 new messages