wxpython AttributeError!

David Bolen db3l at fitlinxx.com
Mon Jan 12 12:00:32 EST 2004


"frank" <frank at pc-nett.no> writes:

> need help with wxpython.
> wxpython code is made with boa-constructor
> 
> when i run the code i get this error message:
(...)
> File "wxFrame1.py", line 157, in _init_ctrls
> EVT_RIGHT_DOWN(self.treeCtrl1, self.OnTreectrl1RightDown)
> AttributeError: wxFrame1 instance has no attribute 'OnTreectrl1RightDown'
(...)
> 
> this is the code have this code:
> 
> self.treeCtrl1 = wxTreeCtrl(id=wxID_WXFRAME1TREECTRL1, name='treeCtrl1',
>               parent=self.splitterWindow1, pos=wxPoint(2, 2),
> size=wxSize(200,
>               610), style=wxTR_HAS_BUTTONS, validator=wxDefaultValidator)
>         self.treeCtrl1.SetFont(wxFont(10, wxSWISS, wxNORMAL, wxNORMAL,
> False,
>               'Microsoft Sans Serif'))
>         EVT_RIGHT_DOWN(self.treeCtrl1, self.OnTreectrl1RightDown)
>         EVT_TREE_SEL_CHANGED(self.treeCtrl1, wxID_WXFRAME1TREECTRL1,
>               self.OnTreectrl1TreeSelChanged)
> 
> and the event EVT_RIGHT_DOWN code is:
> 
> def OnTreectrl1RightDown(self, event):
>           dosomething()
>           event.Skip()
> 
> the "OnTreectrl1RightDown" is in the wxframe class
> what to do?

First is not to snip so much code for your post that context is lost :-)

It's not clear from the above code whether or not your initialization
code and the function definition are within the same class (especially
with the different indentation levels).  If in fact the initialization
code is part of your __init__ definition in wxFrame1, which also holds
the callback function definition, at first glance it looks like it
should be ok.  Or, if the callback definition is in a subclass of
wxFrame1 then you should be ok as well.  But the error you are getting
would imply that 'self' in your initialization code is not the same
object as that which contains the callback definition.

If you could post a more complete snippet of the code (in particular,
at a minimum an unchanged copy of the entire __init__ (or other
function) containing the initialization code, including its enclosing
class definition, as well as the same for the callback function), it
might be easier to see what problem exists.

-- David



More information about the Python-list mailing list