Gabriel Genellina wrote:
En Wed, 04 Mar 2009 03:13:43 -0200, W. eWatson <notval...@sbcglobal.net>
escribió:
I'm converting a Tkinter program (Win XP) that uses widgets that
allows the user to change default values of various parameters like
start and stop time in hh:mm:ss, time of exposure in seconds, and
whether certain options should be on or off. The initial values are
...
don't have to "track" changes to the variables (by example, a "zoom"
slider might provide feedback by zooming the image).
So in the "Options..." menu item in your application, you:
- create the dialog with the required widgets.
- call a method .setvalues(config) which receives a config
object with all the settings, and assigns them to each corresponding
widget.
- have a method .getvalues(config) that does the inverse
operation: from widget contents into the config object.
- display the dialog (you must use a modal loop; see
http://effbot.org/tkinterbook/tkinter-dialog-windows.htm ). If you use
tkSimpleDialog, make sure the .apply() method calls .getvalues
- on exit, the config object contains the final values.
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?
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.) :
======================start
from Tkinter import *
master = Tk()
e = Entry(master)
e.pack()
e.focus_set()
def callback():
print e.get()
b = Button(master, text="get", width=10, command=callback)
b.pack()
mainloop()
=======================end
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:
v = StringVar()
e = Entry(master, textvariable=v)
e.pack()
v.set("a default value")
s = v.get()
"
Why have two ways of doing this?
--
W. eWatson
(121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet
Web Page: <www.speckledwithstars.net/>
--
http://mail.python.org/mailman/listinfo/python-list