Tkinter widgets: Write options *and* option tags dynamically from dictionary?
skywalkerpackage at hotmail.com
Wed Feb 6 07:25:33 EST 2002
thanks very much for your quick response. Now I have get the error
Traceback (most recent call last):
line 301, in RunScript
exec codeObject in __main__.__dict__
line 9, in ?
apply(bt.config, (), optionDict)
File "D:\PYTHON\ACTIVESTATE\PYTHON21\lib\lib-tk\Tkinter.py", line
1085, in configure
TclError: unknown option "-labelText"
although bt is an intstance of LabelEntry and it has the labelText
I think the problem is that I haven't defined a config method in my
Class LabelEntry. It thought that this is not necessary.
When I define a config method, I have the problem that some of the
LabelEntry options (padx and pady) are options for the packer of the
widgets inside (that is, Label and Entry). So, I can't just write
def config(self, kw):
Puh, wired problem for me :<
I think I won't use apply, but use the call by dictionary option
On Wed, 6 Feb 2002 11:18:18 +0000, Eric Brunel
<eric.brunel at pragmadev.com> wrote:
><posted & mailed>
>> def __init__(self, master=None, **kw):
>> Frame.__init__(self, master)
>> self.label = Label(self, text=kw['labelText'])
>> But then, how do I handle default values, and how do I ensure that the
>> objects are created with the right parameters?
>Do not use kw['labelText'], but kw.get('labelText', ''). The get method on
>a dictionary does just what you want. Please refer to:
> - eric -
More information about the Python-list