TkInter: Problem with propagation of resize events through geometry manager hierarchy?

James Stroud jstroud at mbi.ucla.edu
Sun Feb 8 23:58:37 CET 2009


curiouserrandy at gmail.com wrote:
> Thanks!  I hadn't known about the "return 'break'" technique.  But
> I don't follow your sentinel suggestion; how would that sentinel
> ever get reset?

Presumably you would set it from some kind of input. Basically, if you 
don't need to zoom, you wouldn't bother scaling the image. It is the 
scaling step that is expanding your image.

You might want to set any borders to 0.

It seems as if the first time through the event
> chain it'd be set to the sentinel, and the routines that pay
> attention to it would never execute.  What am I missing?
> I tried simply returning 'break' at the end of "refresh()" and
> that made no change in behavior.

You will want to return 'break' at the end of callbacks, like 
display_tag_and_size()

> One thing I've been looking for (including in the source :-J) is
> a description of the precise process that the geometry manager
> goes through in figuring out and then setting sizes for the
> various widgets (on resize or, apparently, startup).  I suspect
> with that + the "return 'break'" technique I could get this to
> work.  But I haven't been having any luck finding that documentation.

I've never found that either. I usually tweak things by trial and error. 
Tkinter (Tk) has some bad habits. Most of the time it is very hard to 
get the precise dimensions of widgets by asking them. The problem is 
exacerbated by platform specific modifications like TkAqua. Ive found 
the best approach is to tweak the math so that the sizing comes out 
consistent and then test and patch for every platform you support. 
Sometimes, if you experiment enough, you can figure out by inference 
what Tk is actually doing under the hood.

The other, more sane option, is to attempt to make guis that don't rely 
on precise size information. Its less satisfying than the pixel level 
control one hopes for, but makes for a faster development process.

Also, you might want to look into Pmw. It has scrolled canvas and 
scrolled frame widgets that might be helpful to you. There is no need to 
reinvent the wheel except for your own enlightenment.

James


-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com



More information about the Python-list mailing list