Tkinter scrolling canvas questions

Eric Brunel eric.brunel at pragmadev.com
Wed Nov 27 11:19:41 EST 2002


Richard Kuhns wrote:

> I'd appreciate any comments or suggestions on the best way to proceed with
> a problem.  I'm fairly new to GUI programming, and I'd appreciate some
> pointers.
> 
> I have a list of lists of (name, variable) tuples I'd like to display.  In
> addition, I want to allow the variable's value to be changed/editted.  It
> looks something like:
> 
> li = [
>       [("a", a), ("b", b), "c", c)],
>       [("d", d), ("e", e), "f", f)]
>     ]
> 
> There's no limit on how many elements li can have, but each element will
> be the same size.
> 
> What I have in mind right now is to create a Frame for each element of the
> toplevel list.  Each Frame would contain Label and Entry widgets for each
> tuple in that element.  After each Frame is created I would then append it
> to the end of a vertically scrollable Canvas.
> 
> Does this sound reasonable?  If so, is there a good way to determine a
> good size for the canvas?  Each frame in the canvas will be a single line;
> how do I query the Label and Entry widgets to determine the size of the
> font being used?  I've been studying the Tkinter section of Programming
> Python 2E but I haven't been able to track down what I need.  The word
> "font" doesn't even appear in the index :(.  Are there any other "gotchas"
> I should watch out for?

The class ScrolledFrame in Pmw is your friend: 
http://pmw.sourceforge.net/doc/ScrolledFrame.html

Download it @ http://pmw.sourceforge.net/

The "real" method would actually involve computing the size of each frame 
you build via frm.winfo_height() (after a frm.update(), or the size will 
always be 0 or 1), add them all and configure your Canvas's scrollregion 
with that. Since Pmw does all the work for you, you really shouldn't 
bother...

HTH
-- 
- Eric Brunel <eric.brunel at pragmadev.com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com



More information about the Python-list mailing list