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

Eric Brunel eric.brunel at pragmadev.com
Mon Feb 4 05:30:14 EST 2002


Hi,

> Laura, I don't think,
>
> widget=widgetType(master, **mydict)
>
> is necessary. I have tried
>
> widget=widgetType(master, mydict)
>
> with mydict={'text':'hello', 'relief':'sunken'}. It worked without the
> two stars.

The second form is Tkinter specific. All methods/constructors are defined
like that:
def m(parent, optionDict={}, **options)
So it allows to pass the options either as a regular dictionary, or as named
parameters.

> Aren't the two stars just necessary for function calls with variable
> length key parameters?

I admit I didn't know about the m(**dict) syntax, but in the general case,
it is indeed required. Using the "apply" stuff also works.

HTH
 - eric -





More information about the Python-list mailing list