Hi,
hi i want know how work with the events in wxpython for example i have
two classes in the frame class hve the “self.Bind” event and the other
class have the definition of the event this can pass without error?
like that…
class Tree(wx.TreeCtrl):
def __init__(self, parent, id):
wx.TreeCtrl.__init__(self, parent, id)
def OnActivated(self, event):
pass
class Frame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__iniit__(self, parent, id, title)
self.tree = Tree(self, -1)
self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnActivated)
You can’t really do that. What you really want to do is to either put the event binding for the widget in the widget’s class or the event handler in the class that has the widget instance. Here are two examples illustrating both:
# Putting the event handler in the frame
class Tree(wx.TreeCtrl):
def __init__(self, parent, id):
wx.TreeCtrl.__init__(self, parent, id)
class Frame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__iniit__(self, parent, id, title)
self.tree = Tree(self, -1)
self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnActivated)
def OnActivated(self, event):
pass
# Putting the event handler and the binding in the tree control
class Tree(wx.TreeCtrl):
def __init__(self, parent, id):
wx.TreeCtrl.__init__(self, parent, id)
self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnActivated)
def OnActivated(self, event):
pass
class Frame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__iniit__(self, parent, id, title)
self.tree = Tree(self, -1)
Finally, there’s a third option which is to use pubsub. I hope that helps!
···
On Sun, Sep 13, 2009 at 1:30 PM, iozk_Live iozk117@gmail.com wrote:
Mike Driscoll
Blog: http://blog.pythonlibrary.org