[wxPython-users] wx.Notebook and button events

Johannes Bauer jb at 5pm.de
Thu Nov 22 03:47:09 PST 2007


Hello Robin,

thanks a lot for your answer. Binding the events to the buttons works fine.
It seems that wxGalde can't generate code for this, but I can delete the
event bindings there and manually add them to the code.

Again, thank you - my problem has been solved.

Bye,
Johannes

>> Hello,
>>
>> I happened upon a rather strange behaviour while programming wxPython
>> using SPE on Linux, using wxPython 2.8.4.0 and Python 2.5.
>>
>> The example code below creates a simple frame containing a wx.Notebook
>> with two tabs. Each tab has a button, both with the same label.
>>
>> Now, when I klick either one of those buttons, events for both of them
>> are generated - first the one on the second tab, then the one on the
>> first.
>>
>> Is this expexted behaviour?
>
> Yes, because they both have the same ID and the event handlers are bound
>   at a point further up the containment hierarchy that both buttons have
> in common.  The easiest way to do what you want is to change where you
> attach the event binding, such that they are not bound to common place
> in the tree.  You can either do it by binding to the buttons (shown) or
> to the panels:
>
>          self.button_1.Bind(wx.EVT_BUTTON, self.button_1_clicked)
>          self.button_2.Bind(wx.EVT_BUTTON, self.button_2_clicked)
>
> See http://wiki.wxpython.org/self.Bind_vs._self.button.Bind







More information about the wxpython-users mailing list