473,325 Members | 2,308 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

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 2945
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Adonis | last post by:
I wish to manually move widgets in Tkinter, now I have successfully done it, but with odd results, I would like to move the widgets with a much smoother manner, and better precision. Any help is...
7
by: William Gill | last post by:
Is there a simple way to cut and paste from a tkinter text widget to an entry widget? I know I could create a mouse button event that triggers a popup (message widget) prompting for cut/paste in...
6
by: John Bowman | last post by:
Hi All, I must be missing something really obvious, so I'd appreciate someone helping me out. I have a simple Windows form that currently only has a title bar (aka the Text Property is set) and...
0
by: Sam Barham | last post by:
I have a ListView control, for which I have overwritten the WndProc method to gain access to the WM_PAINT message and generate my own OnPaint and OnPaintBackground messages, in order to colour the...
13
by: Martin Ho | last post by:
I know this must be trivial for many of you. But I am playing with this and can't figure it out. I have a form, on that form is one panel which has 3 textboxes, when I run my program and...
3
by: aum | last post by:
Hi, Can anyone please recommend a widget library for text console, that works not only on *nix systems but windows /as well/? I'm looking for something a bit higher-level than pure curses,...
1
by: Eric Wong | last post by:
Using Tkinter, I have a Canvas with vertical Scrollbar attached. At runtime, I dynamically create Checkboxes on the Canvas, each one on a different row. When I add a lot of Checkboxes, instead of...
2
by: nholtz | last post by:
Is there any way to delete a widget (window) from a Text widget, and then add it back to the Text, without re-creating the original widget. For example, I think I would like to do something like...
9
by: dli07 | last post by:
Hello, I'm trying to convert a piece of code that creates a dynamic vertical resizing bar in a table from internet explorer to firefox. It's based on a post from...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.