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 set in the code. I
can pretty well modify matters, so the values of parameters can be saved
and restored from a config file for use outside the widgets (dialogs).
Basically, a list of parameter names and values are kept in the file.
Do you want to build a generic dialog (that is, do you want to *build* the
dialog depending on what you find in the file)? Or does the dialog already
exist? (In the former case, if you add a new parameter in the file, a new
widget -of an adequate type- is created)
I assume this is not the case, and you have a fixed dialog containing a
known set of widgets that represent a known set of parameters.
You need some object that stores the config values, and read/save them
from the config file. And a dialog that shows the config info and let the
user modify it. You don't need any StringVar/IntVar/whatever, if you 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.
--
Gabriel Genellina
--
http://mail.python.org/mailman/listinfo/python-list