Help Requested
I'm having a problem with the wxPython framework, and I thought this might be a decent place to go to for help. I'm not sure if this is a FAQ, so I didn't add it to that page (but feel free to move it there if appropriate).
My problem is that when I use a wxSplitterWindow the components placed within the panels are not "active". I'm sure it's something simple, but I couldn't figure it out. I reduced the problem to a fairly trivial example program:
Example Program
1 from wxPython.wx import *
2
3 class MainWindow(wxFrame):
4 def __init__(self, parent, id, title):
5 # --------- Call Parent Init -----------
6 wxFrame.__init__(self, parent, -1, title)
7
8 # --------- Create Pane Contents -----------
9 TEST_TO_RUN = 1
10 if TEST_TO_RUN == 0:
11 self.mainPane = wxButton(self, id=-1, label="Click Me")
12 mainWindowContents = self.mainPane
13 elif TEST_TO_RUN == 1:
14 splitter = wxSplitterWindow(self, -1)
15
16 self.leftPane = wxButton(self, id=-1, label="Left")
17 self.rightPane = wxButton(self, id=-1, label="Right")
18
19 splitter.SplitVertically(self.leftPane, self.rightPane)
20 splitter.SetSashPosition(200)
21 splitter.SetMinimumPaneSize(20)
22
23 mainWindowContents = splitter
24
25
26 # -- mainWindowContents fills the window --
27 sizer = wxBoxSizer(wxVERTICAL)
28 sizer.Add(mainWindowContents, 1, wxEXPAND)
29 self.SetSizer(sizer)
30 self.SetAutoLayout(true)
31
32 # --------- Set Up Window Events -----------
33 EVT_CLOSE(self, self.onCloseWindow)
34
35 # --------- Show the frame -----------
36 self.Show(true)
37
38 def onCloseWindow(self, event):
39 self.Destroy()
40
41
42 class App(wxApp):
43 def OnInit(self):
44 frame = MainWindow(None, -1, 'Title')
45 self.SetTopWindow(frame)
46 return true
47
48 if __name__ == '__main__':
49 app = App(0)
50 app.MainLoop()
Replicating the Problem
To test this, set TEST_TO_RUN to 0, and observe that the button which is created can be "clicked". Then change it to 1, and the two buttons created will NOT react when clicked.
What's the simple bit of initialization that I'm ommitting?
Answer
(Thanks to Robin Dunn for this answer.)
The buttons should have the splitter as their parent window.
See also PortingYourBrainFromTkinterToWxPython.