Resizing widgets in text windows

James Stroud jstroud at
Sat Jan 27 04:52:20 CET 2007

deacon.sweeney at 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>'.


from Tkinter import *

def config(t):
   def _r(e, t=t):
     geom = e.widget.wm_geometry()
     geom = geom.split('+')[0]
     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?


> Any help would be greatly appreciated.
> Deacon Sweeney

More information about the Python-list mailing list