Re: Looking for a General Method to Configure Tkinter Widgets
odeits wrote: On Mar 2, 7:14 am, W. eWatson notval...@sbcglobal.net wrote: 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/ I am sorry, I am a bit confused. Is your question how to preserve the value and/or type of the data in the config file? Or are you having trouble getting the values from the file to the widget? I'm probably confused too. :-) Let's try this. In s=dialog.stopVar.get() I'd like to eliminate the statement and replace it with something like: s=dialog. + stopV.get() )and execute that--I'm aware of the exec operation--problems) where StopV is a string name taken from the config file. That is, in the config file there would be something like: stop_time = 18:00:00, stopV. Initially, when starting the program, reading that line would create a self.stop_time variable with the value 18:00:00 (string). To communicate with the dialog widget where the user enters a new value, I need to use control variables. but ones that are not in the code itself. Instead, I would like to manufacture them from what I see in the config file. -- 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
Re: Looking for a General Method to Configure Tkinter Widgets
On Tue, 03 Mar 2009 18:58:47 -, W. eWatson notval...@sbcglobal.net wrote: I'm probably confused too. Let's try this. In s=dialog.stopVar.get() I'd like to eliminate the statement and replace it with something like: s=dialog. + stopV.get() )and execute that--I'm aware of the exec operation--problems) where StopV is a string name taken from the config file. That is, in the config file there would be something like: stop_time = 18:00:00, stopV. I'm trying to think of a case where opening up this security hole is even marginally wise, and I'm failing. If you absolutely must prat around with indirections like this, wouldn't s = getattr(dialog, variable_containing_the_string_stopV).get() be a much less unsafe idea? -- Rhodri James *-* Wildebeeste Herder to the Masses -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for a General Method to Configure Tkinter Widgets
W. eWatson wrote: odeits wrote: On Mar 2, 7:14 am, W. eWatson notval...@sbcglobal.net wrote: 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/ I am sorry, I am a bit confused. Is your question how to preserve the value and/or type of the data in the config file? Or are you having trouble getting the values from the file to the widget? I'm probably confused too. :-) Let's try this. In s=dialog.stopVar.get() I'd like to eliminate the statement and replace it with something like: s=dialog. + stopV.get() )and execute that--I'm aware of the exec operation--problems) where StopV is a string name taken from the config file. That is, in the config file there would be something like: stop_time = 18:00:00, stopV. Initially, when starting the program, reading that line would create a self.stop_time variable with the value 18:00:00 (string). To communicate with the dialog widget where the user enters a new value, I need to use control variables. but ones that are not in the code itself. Instead, I would like to manufacture them from what I see in the config file. I've been told that there may be another way to communicate with Tkinter than control variables. I'm not quite sure what, but will probably know tomorrow. I think I will discontinue this thread, and re-post if necessary. -- 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
Looking for a General Method to Configure Tkinter Widgets
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/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for a General Method to Configure Tkinter Widgets
On Mar 2, 7:14 am, W. eWatson notval...@sbcglobal.net wrote: 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/ I am sorry, I am a bit confused. Is your question how to preserve the value and/or type of the data in the config file? Or are you having trouble getting the values from the file to the widget? -- http://mail.python.org/mailman/listinfo/python-list