Tkinter widgets: Write options *and* option tags dynamically from dictionary?

Johannes Eble skywalkerpackage at hotmail.com
Fri Feb 1 14:20:26 CET 2002


Hello all,

In Tkinter the widgets are created in the form:

wgt = Widget(master, option_tag1 = option1,  option_tag2 =
option2,...)

I want to create widgets dynamically. Therefore I have created a
dictionary for the options (well, it is a list of lists of lists which
have this dictionary included, but I will keep it simple here). The
problem is that not only the options are unknown at compile time, but
also the *option tags*. For example in Button(root, text='Hello') also
the *text* option tag should be taken from the keys of the options
dictionary. 

This is hardcoded:

from Tkinter import *
root = Tk()
bt = Button(root, text='Hello') 
bt.pack(side=TOP)
root.mainloop()


When I change it to something like

...
dictOptions = {text: 'Hello',....}
bt.config(?)
...

,Python complains that there is no defined symbol text. Also, I
wouldn't know what to write in bt.config(....)

On the other hand, I have tried to write

dictOptions={'text':'Hello'} and compose the string "text='Hello'" on
the fly, but then I built a button with the text "text='Hello'".


So, how can I change the options and the option tags dynamically?


Any help would be appreciated.


ByeBye

Johannes



More information about the Python-list mailing list