wxpython AttributeError!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • frank

    wxpython AttributeError!

    need help with wxpython.
    wxpython code is made with boa-constructor

    when i run the code i get this error message:

    Traceback (most recent call last):
    File "wxApp1.py" , line 24, in ?
    main()
    File "wxApp1.py" , line 20, in main
    application = BoaApp(0)
    File "K:\Python23\li b\site-packages\wxPyth on\wx.py", line 1945, in __init__
    _wxStart(self.O nInit)
    File "wxApp1.py" , line 13, in OnInit
    self.main = wxFrame1.create (None)
    File "wxFrame1.p y", line 12, in create
    return wxFrame1(parent )
    File "wxFrame1.p y", line 220, in __init__
    self._init_ctrl s(parent)
    File "wxFrame1.p y", line 157, in _init_ctrls
    EVT_RIGHT_DOWN( self.treeCtrl1, self.OnTreectrl 1RightDown)
    AttributeError: wxFrame1 instance has no attribute 'OnTreectrl1Rig htDown'
    23:06:44: Debug: c:\PROJECTS\wx\ src\msw\app.cpp (439):
    'UnregisterClas s(canvas)' failed with error 0x00000584 (class still has open
    windows.).

    this is the code have this code:

    self.treeCtrl1 = wxTreeCtrl(id=w xID_WXFRAME1TRE ECTRL1, name='treeCtrl1 ',
    parent=self.spl itterWindow1, pos=wxPoint(2, 2),
    size=wxSize(200 ,
    610), style=wxTR_HAS_ BUTTONS, validator=wxDef aultValidator)
    self.treeCtrl1. SetFont(wxFont( 10, wxSWISS, wxNORMAL, wxNORMAL,
    False,
    'Microsoft Sans Serif'))
    EVT_RIGHT_DOWN( self.treeCtrl1, self.OnTreectrl 1RightDown)
    EVT_TREE_SEL_CH ANGED(self.tree Ctrl1, wxID_WXFRAME1TR EECTRL1,
    self.OnTreectrl 1TreeSelChanged )

    and the event EVT_RIGHT_DOWN code is:

    def OnTreectrl1Righ tDown(self, event):
    dosomething()
    event.Skip()

    the "OnTreectrl1Rig htDown" is in the wxframe class
    what to do?
    thanx in advance


  • David Bolen

    #2
    Re: wxpython AttributeError!

    "frank" <frank@pc-nett.no> writes:
    [color=blue]
    > need help with wxpython.
    > wxpython code is made with boa-constructor
    >
    > when i run the code i get this error message:[/color]
    (...)[color=blue]
    > File "wxFrame1.p y", line 157, in _init_ctrls
    > EVT_RIGHT_DOWN( self.treeCtrl1, self.OnTreectrl 1RightDown)
    > AttributeError: wxFrame1 instance has no attribute 'OnTreectrl1Rig htDown'[/color]
    (...)[color=blue]
    >
    > this is the code have this code:
    >
    > self.treeCtrl1 = wxTreeCtrl(id=w xID_WXFRAME1TRE ECTRL1, name='treeCtrl1 ',
    > parent=self.spl itterWindow1, pos=wxPoint(2, 2),
    > size=wxSize(200 ,
    > 610), style=wxTR_HAS_ BUTTONS, validator=wxDef aultValidator)
    > self.treeCtrl1. SetFont(wxFont( 10, wxSWISS, wxNORMAL, wxNORMAL,
    > False,
    > 'Microsoft Sans Serif'))
    > EVT_RIGHT_DOWN( self.treeCtrl1, self.OnTreectrl 1RightDown)
    > EVT_TREE_SEL_CH ANGED(self.tree Ctrl1, wxID_WXFRAME1TR EECTRL1,
    > self.OnTreectrl 1TreeSelChanged )
    >
    > and the event EVT_RIGHT_DOWN code is:
    >
    > def OnTreectrl1Righ tDown(self, event):
    > dosomething()
    > event.Skip()
    >
    > the "OnTreectrl1Rig htDown" is in the wxframe class
    > what to do?[/color]

    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

    Comment

    Working...