En Wed, 04 Mar 2009 12:12:50 -0200, W. eWatson <notval...@sbcglobal.net>
escribió:
That's fine, but I think my problem boils down to one question. There
seem to be two ways to communicate with a dialog (I mean a collection of
widgets assembled in a window that requires the user enter various
parameters, integers, strings, yes/no button, etc.): 1. a callback and
2. control variables. Which one should be used?
The simplest way that probably works. The one you feel most comfortable
with. The one best fits your application. There is no single answer.
To be more explicit, look at this code from your source above
<http://effbot.org/tkinterbook/entry.htm>. (This is about the simplest
"dialog" one can have.) :
[...code...]
Note that above this example, the author mentions:
"You can also bind the entry widget to a StringVar instance, and set or
get the entry text via that variable:
Why have two ways of doing this?
You may have some related widgets, and want to keep them syncronized. By
example, a slider 0-100 and a text entry for some percentage. Moving the
slider changes the number displayed, and editing the number moves the
slider accordingly. There are other ways of doing the same: you may react
to some events in one widget, and alter the other accordingly. But:
- that requires that you know *which* events actually modify the value
- increases coupling between all your widgets (consider what happens when
you want to add an image showing the effect of moving the slider)
So, in some cases, it is more convenient to use bound variables. You may
consider this as a micro-application of the Model-View-Controller pattern.
That said, I seldom use bound variables (but I seldom write GUIs using
Tkinter either).
--
Gabriel Genellina
--
http://mail.python.org/mailman/listinfo/python-list