access properties of parent widget in Tkinter
William Gill
noreply at gcgroup.net
Thu Jun 16 13:28:19 EDT 2005
Kent Johnson wrote:
> William Gill wrote:
>
>> I am trying to get & set the properties of a widget's parent widget.
>> What I have works, but seems like a long way around the block. First
>> I get the widget name using w.winfo_parent(), then i convert the name
>> to a reference using nametowidget().
>>
>> self.nametowidget(event.widget.winfo_parent()).hasChanged= True
>
>
> Personally I think it is bad design for a widget to assume anything
> about its enclosing environment. What about passing a StringVar or
> IntVar to the child widget and letting it work with that?
>
> Kent
I stumbled across the widget.master attribute. so
self.nametowidget(event.widget.winfo_parent()).hasChanged = True
can be re-written as
self.master.hasChanged = True
I thought I was doing things the indirect way.
Thanks everyone for your help.
I'm still interested in if anyone thinks this is "bad practice", and why.
Bill
More information about the Python-list
mailing list