469,636 Members | 1,943 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,636 developers. It's quick & easy.

Resizing widgets in text windows

Hi, I've been searching for a .resize()-like function to overload much
like can be done for the delete window protocol as follows:

toplevel.protocol("WM_DELETE_WINDOW", callback)

I realize that the pack manager usually handles all of the resize
stuff, but I've found an arrangement that the pack manager fails for.
That is, if one embeds a canvas into a window created inside a text
widget, then resize the text widget (via its container), the canvas and
its container windows do not resize. So I need to resize the window
that the canvas is embedded in. The most obvious way of doing this
would be as above, but there does not seem to be an equivalent to the
"WM_DELETE_WINDOW" protocol for resizing.

Any help would be greatly appreciated.

Deacon Sweeney

Jan 26 '07 #1
5 2797
de************@gmail.com wrote:
Hi, I've been searching for a .resize()-like function to overload much
like can be done for the delete window protocol as follows:

toplevel.protocol("WM_DELETE_WINDOW", callback)

I realize that the pack manager usually handles all of the resize
stuff, but I've found an arrangement that the pack manager fails for.
That is, if one embeds a canvas into a window created inside a text
widget,
Your meaning here is unclear. How is it possible to have "a window
created inside a text widget"?
then resize the text widget (via its container), the canvas and
its container windows do not resize. So I need to resize the window
that the canvas is embedded in.
Try the Toplevel.wm_geometry() function.
The most obvious way of doing this
would be as above, but there does not seem to be an equivalent to the
"WM_DELETE_WINDOW" protocol for resizing.
Do you want to detect when a window is resized or do you want to resize
a window programatically.

If the former, bind the Toplevel to '<Configure>'.

E.g.

from Tkinter import *

def config(t):
def _r(e, t=t):
geom = e.widget.wm_geometry()
geom = geom.split('+')[0]
t.wm_geometry(geom)
print 'resized %s to %s' % (t, geom)
return _r

tk = Tk()
tk.title('resize me')
t2 = Toplevel(tk)
t2.title('I get resized')
tk.bind('<Configure>', config(t2))
Is that cool or what?

James
Any help would be greatly appreciated.

Deacon Sweeney
Jan 27 '07 #2
On Fri, 26 Jan 2007 22:35:20 +0100, <de************@gmail.comwrote:
Hi, I've been searching for a .resize()-like function to overload much
like can be done for the delete window protocol as follows:

toplevel.protocol("WM_DELETE_WINDOW", callback)

I realize that the pack manager usually handles all of the resize
stuff, but I've found an arrangement that the pack manager fails for.
That is, if one embeds a canvas into a window created inside a text
widget, then resize the text widget (via its container), the canvas and
its container windows do not resize.
Supposing you call "embedding" inserting a widget in the text via the
window_create method, why should they? Embedding a window in a Text is
used to put some arbitrary widget in the middle of the text it contains.
So the embedded widget has no reason to grow or shrink with the parent
Text widget: it just moves with the text.
So I need to resize the window
that the canvas is embedded in. The most obvious way of doing this
would be as above, but there does not seem to be an equivalent to the
"WM_DELETE_WINDOW" protocol for resizing.
As James said, the <Configureevent is your friend. But I'm not sure I
understand your use case...

HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
Jan 29 '07 #3
On Jan 26, 10:52 pm, James Stroud <jstr...@mbi.ucla.eduwrote:
deacon.swee...@gmail.com wrote:
Hi, I've been searching for a .resize()-like function to overload much
like can be done for the delete window protocol as follows:
toplevel.protocol("WM_DELETE_WINDOW", callback)
I realize that the pack manager usually handles all of the resize
stuff, but I've found an arrangement that the pack manager fails for.
That is, if one embeds a canvas into a window created inside a text
widget,

Your meaning here is unclear. How is it possible to have "a window
created inside a text widget"?
using the create_window function, as below.
>
then resize the text widget (via its container), the canvas and
its container windows do not resize. So I need to resize the window
that the canvas is embedded in.

Try the Toplevel.wm_geometry() function.
The most obvious way of doing this
would be as above, but there does not seem to be an equivalent to the
"WM_DELETE_WINDOW" protocol for resizing.

Do you want to detect when a window is resized or do you want to resize
a window programatically.

If the former, bind the Toplevel to '<Configure>'.

E.g.

from Tkinter import *

def config(t):
def _r(e, t=t):
geom = e.widget.wm_geometry()
geom = geom.split('+')[0]
t.wm_geometry(geom)
print 'resized %s to %s' % (t, geom)
return _r

tk = Tk()
tk.title('resize me')
t2 = Toplevel(tk)
t2.title('I get resized')
tk.bind('<Configure>', config(t2))

Is that cool or what?
Yes, this is exactly what I was looking for. Thanks.
James
Any help would be greatly appreciated.
DeaconSweeney


Jan 30 '07 #4
On Jan 29, 3:33 am, "Eric Brunel" <eric_bru...@despammed.comwrote:
On Fri, 26 Jan 2007 22:35:20 +0100, <deacon.swee...@gmail.comwrote:
Hi, I've been searching for a .resize()-like function to overload much
like can be done for the delete window protocol as follows:
toplevel.protocol("WM_DELETE_WINDOW", callback)
I realize that the pack manager usually handles all of the resize
stuff, but I've found an arrangement that the pack manager fails for.
That is, if one embeds a canvas into a window created inside a text
widget, then resize the text widget (via its container), the canvas and
its container windows do not resize.

Supposing you call "embedding" inserting a widget in the text via the
window_create method, why should they? Embedding a window in a Text is
used to put some arbitrary widget in the middle of the text it contains.
So the embedded widget has no reason to grow or shrink with the parent
Text widget: it just moves with the text.
So I need to resize the window
that the canvas is embedded in. The most obvious way of doing this
would be as above, but there does not seem to be an equivalent to the
"WM_DELETE_WINDOW" protocol for resizing.

As James said, the <Configureevent is your friend. But I'm not sure I
understand your use case...

HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
I'm using a text widget to hold a set of plots, one plot per line,
such that the scrolling capability of the text widget can be taken
advantage of to display only a subset of the plots at any given time.
In the analyses my program automates, there are at least several plots
are typically loaded into the text widget. This works out splendidly,
but the width of the plots has thus far been a static thing. Now, I'll
be able to adjust the plots widths so that when the owner window is
resized, the width of each plot in the text widget is adjusted and the
plot continues to occupy the entire text widget but no more, making
for a much more professional looking product.

I didn't mean to imply that create_window widgets should automatically
resize with the toplevel... I just couldn't find any way to force it.

Muchas gracias.

Deacon


Jan 30 '07 #5
On Tue, 30 Jan 2007 23:13:07 +0100, <de************@gmail.comwrote:
I'm using a text widget to hold a set of plots, one plot per line,
such that the scrolling capability of the text widget can be taken
advantage of to display only a subset of the plots at any given time.
In the analyses my program automates, there are at least several plots
are typically loaded into the text widget. This works out splendidly,
but the width of the plots has thus far been a static thing. Now, I'll
be able to adjust the plots widths so that when the owner window is
resized, the width of each plot in the text widget is adjusted and the
plot continues to occupy the entire text widget but no more, making
for a much more professional looking product.
IMHO, "abusing" the text widget to do that is quite likely to cause
problems in the future. For this use case, I would have used a Canvas with
scrollbars containing a Frame where the plots are packed or gridded
vertically. The Canvas's scrollregion should then be adjusted each time a
plot is added, removed or resized, and you'd still have to use the
<Configureevent to resize the Frame to the Canvas's width. But at least,
that's what Canvases and Frames are for; the Text widget is for... well,
displaying text. Also note that Pmw (http://pmw.sourceforge.net/) has a
ScrolledFrame megawidget that just does what you want.
Muchas gracias.
You're welcome.

HTH again...
--
python -c "print ''.join([chr(154 - ord(c)) for c in
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
Jan 31 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Adonis | last post: by
7 posts views Thread by William Gill | last post: by
6 posts views Thread by John Bowman | last post: by
3 posts views Thread by aum | last post: by
1 post views Thread by Eric Wong | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.