ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Anybody know how to use the Python exec statement? I'm working on a GUI, and need to change the colors/states of a number of buttons when one is pushed. If I print cmd instead of exec, the lines come out right.
Traceback (most recent call last):
File "/usr/lib/python2.2/lib-tk/Tkinter.py", line 1316, in __call__
return apply(self.func, args)
File "weather2.py", line 58, in wd_ne
File "<string>", line 1, in ?
File "/usr/lib/python2.2/lib-tk/Tkinter.py", line 1109, in configure
TclError: unknown option "-color"
I'm looking for a better way then writing out...
...eight times, and five similar lines to change states on air_pressure buttons, and five similar lines to change states for pressure_change buttons, for each of the eight wind_directions. What is that...? Nearly 160 lines?
A better way may be to change your algorithm. Maybe keep a tract of current_red_button and pushed_button, and only change their colours around.
Or alter the button pushed event responce to something like reset_all_buttons(), make_button_red(this).
This is my first GUI program, so I knew it would be ugly. I finally found it in the Tkinter module doc.
Of course, I had already implemented a way like Proud had suggested... Each button push first calls a function that turns all the buttons black, then turns the one pushed red. Only need to write out the color='black' lines once.
I still might use the idea above though, so I can pass any button_name, attribute, and setting to a function. Such as ... button_config(ap_hi_button, state, NORMAL)