[Tutor] Dynamic TKinter widgets?
ALAN GAULD
alan.gauld at btinternet.com
Mon Nov 26 00:49:09 CET 2012
CC'ing the list...
I know you can use images instead of text with Labels, like you can with Buttons.
>The advantage of a Text widget, in this case, is that you can use both in the same widget.
>That way, I don't need to worry about how widgets are displayed, shuffled around, and
>undisplayed during runtime. One widget should handle everything.
>
>Don't get hung up on the number of widgets. In the scheme of things widgets are not
expensive. Create them as you need them, delete them when you are done. Layout
managers are there to manage the layout for you. if you can define the layout in terms
of a grid then you can fill the grid with blanks to hold the shape and add/remove
widgets as you like.
If you use pack you can either force the containing frame to a fixed size or allow it
to grow/shrink with the widgets. Either approach can work.
This is standard? That's interesting to know. The biggest issue I'm having here is scalability.
>Each new spread is going to need a new frame widget, which in turn will need
>(number of cards in spread)*2 more widgets.
>
>But that's how many? If its getting up beyond a couple of thousand then you might
have a problem. If its less than a hundred its not an issue. In between you might want
to be a bit clever.
As noted above, the Text widget solution only needs one.
>
>Actually it probably needs more. Each image is a widget too, so you just organise
the widgets inside a Text instead of inside a Frame or Canvas. All these things are
just containers for more widgets. Frames are designed to hold widgets, end of story.
Text is designed to *display* images and text - usually within a Frame. Canvas is
designed to *display* images and graphics shapes. If you want your images joined
or surrounded by lines/circles etc then go with Canvas. If you need to include
explanatory text around the images use a Text. If you want to create a reusable
widget that you can use in multiple screens or hot swap with other variants of
the same go with a Frame and build a display widget hierarchy. If you just want to
display a bunch of images it doesn't matter much which one you pick.
I repeat, don't sweat over the widget count, that's not usually an issue.
Alan G.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20121125/52052eee/attachment-0001.html>
More information about the Tutor
mailing list