Looking for a General Method to Configure Tkinter Widgets

W. eWatson notvalid2 at sbcglobal.net
Mon Mar 2 10:14:12 EST 2009


I'm modifying a Tkinter Python program that uses hard coded initial values 
for several widgets. For example, latitude = 40. My plan is to put the names 
and values for configuration purposes into a file. For example, a pseudo 
statement like the one just given. ConfigObj provides a mechanism for it.

I am only at an early stage of learning Tkinter, but it looks like a hang up 
is in the use of control variables passed between widgets and non-Tkinter 
objects that setup up the widget and retrieve the changed values. Roughly, 
the main loop contains code like self.longitude = 40. Non-Tkinter objects 
set up the parameters to the widgets, and when a widget* is complete the 
setup program resets the main loop globals. As I see it, it looks like 
IntVar, etc. used must be hard coded, as in the original program, to 
preserve types like boolean, strings, integers, floats, etc. It's either 
that or use of eval or some like function. Comments?

* For example, in one setup program, I see code like this after its call to 
a dialog returns:

         try:
             s = dialog.stopVar.get()
             d = [ int(x) for x in s.split(":") ]
             self.stop_time = datetime.time(d[0],d[1],d[2])

stop_time is a string like "10:30:15".
-- 
                                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/>




More information about the Python-list mailing list