OOP and Tkinter
Kent Johnson
kent at kentsjohnson.com
Mon May 15 15:00:50 EDT 2006
Ronny Mandal wrote:
> file front_ui.py:
>
> class Front(object):
> _images = [] # Holds image refs to prevent GC
> def __init__(self, root):
> # Widget Initialization
> self._listbox_1 = Tkinter.Listbox(root,
> height = 0,
> width = 0,
> ...
> )
>
> other file:
>
> from Front_ui import Front
>
> class CustomFront(Front):
> Front._listbox_1.insert( 0, 'foo' )
>
> ...
> ...
> File "H:\My Documents\Komodo\Front.py", line 63, in CustomFront
> Front._listbox_1.insert( 0, foo' )
> AttributeError: type object 'Front' has no attribute '_listbox_1'
>
>
> i.e., it cannot find the listbox! Strange, both files is in the same
> folder. What is wrong here?
_listbox_1 is an instance attribute, not a class attribute. You need to
refer to self._listbox_1 from a CustomFront method, or change _listbox_1
to a class attribute if that is what you really want.
Kent
More information about the Python-list
mailing list