Johannes,
···
-----Original Message-----
From: Johannes Bauer [mailto:jb@5pm.de]
Sent: Tuesday, November 20, 2007 3:00 PM
To: wxpython-users@lists.wxwidgets.org
Subject: wx.Notebook and button eventsHello,
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? Am I doing something wrong?
Thank you for your answers,
Johannes
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# generated by wxGlade 0.6 on Tue Nov 20 21:26:17 2007import wx
# begin wxGlade: extracode
# end wxGladeclass MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: MyFrame.__init__
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.notebook_1 = wx.Notebook(self, -1, style=0)
self.notebook_1_pane_2 = wx.Panel(self.notebook_1, -1)
self.notebook_1_pane_1 = wx.Panel(self.notebook_1, -1)
self.panel_1 = wx.Panel(self.notebook_1_pane_1, -1)
self.button_1 = wx.Button(self.notebook_1_pane_1,
wx.ID_OK, "")
self.panel_4 = wx.Panel(self.notebook_1_pane_1, -1)
self.panel_3 = wx.Panel(self.notebook_1_pane_2, -1)
self.button_2 = wx.Button(self.notebook_1_pane_2,
wx.ID_OK, "")
self.panel_2 = wx.Panel(self.notebook_1_pane_2, -1)self.__set_properties()
self.__do_layout()self.Bind(wx.EVT_BUTTON, self.button_1_clicked,
self.button_1)
self.Bind(wx.EVT_BUTTON, self.button_2_clicked,
self.button_2)
# end wxGladedef __set_properties(self):
# begin wxGlade: MyFrame.__set_properties
self.SetTitle("frame_1")
self.SetSize((400, 300))
# end wxGladedef __do_layout(self):
# begin wxGlade: MyFrame.__do_layout
sizer_1 = wx.BoxSizer(wx.VERTICAL)
sizer_2_copy = wx.BoxSizer(wx.VERTICAL)
sizer_2 = wx.BoxSizer(wx.VERTICAL)
sizer_2.Add(self.panel_1, 1, wx.EXPAND, 0)
sizer_2.Add(self.button_1, 0,
wx.ALIGN_CENTER_HORIZONTAL| wx.ALIGN_CENTER_VERTICAL, 0)
sizer_2.Add(self.panel_4, 1, wx.EXPAND, 0)
self.notebook_1_pane_1.SetSizer(sizer_2)
sizer_2_copy.Add(self.panel_3, 1, wx.EXPAND, 0)
sizer_2_copy.Add(self.button_2, 0,
wx.ALIGN_CENTER_HORIZONTAL| wx.ALIGN_CENTER_VERTICAL, 0)
sizer_2_copy.Add(self.panel_2, 1, wx.EXPAND, 0)
self.notebook_1_pane_2.SetSizer(sizer_2_copy)
self.notebook_1.AddPage(self.notebook_1_pane_1, "tab1")
self.notebook_1.AddPage(self.notebook_1_pane_2, "tab2")
sizer_1.Add(self.notebook_1, 1, wx.EXPAND, 0)
self.SetSizer(sizer_1)
self.Layout()
# end wxGladedef button_1_clicked(self, event): # wxGlade:
MyFrame.<event_handler>
print "Event handler `button_1_clicked' not implemented!"
event.Skip()def button_2_clicked(self, event): # wxGlade:
MyFrame.<event_handler>
print "Event handler `button_2_clicked' not implemented!"
event.Skip()# end of class MyFrame
if __name__ == "__main__":
app = wx.PySimpleApp(0)
wx.InitAllImageHandlers()
frame_1 = MyFrame(None, -1, "")
app.SetTopWindow(frame_1)
frame_1.Show()
app.MainLoop()
The issue is that you gave both buttons the same id. Use wx.ID_ANY
instead.
Mike