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

Johannes Eble skywalkerpackage at
Fri Feb 1 08:20:26 EST 2002

Hello all,

In Tkinter the widgets are created in the form:

wgt = Widget(master, option_tag1 = option1,  option_tag2 =

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

This is hardcoded:

from Tkinter import *
root = Tk()
bt = Button(root, text='Hello') 

When I change it to something like

dictOptions = {text: 'Hello',....}

,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.



More information about the Python-list mailing list