I am having trouble with this code. Please feel free to run it as it does work.
All i want it to do is create a frame with a sub window however i want the sub window to contain a splitter window as a child of it. That is what i have tried to do below but it just creates a little square at the top left of the screen with my splitter window and sub panels squashed up into it
Something to note: The splitter window works fine if i add the splitter window to the top level frame instead of my sub window (RootWindow)
but i really need the splitter window to be a child of wx.Window or even wx.Panel but i dont know how to avoid this squashing problem that is specific to working with wx.Window or wx.Panel as apposed to wx.Frame.
Any thoughts?
Mark
#Code Starts
import wx
ID_ABOUT = 101
class MainFrame(wx.Frame):
def __init__(self, parent, ID, title):
wx.Frame.__init__(self, parent, ID, title, wx.DefaultPosition, wx.Size(200, 150))
#add Container window that holds the splitter window and sub panels
self.RootWindow = RootWindow(self, -1)
class MainApp(wx.App):
def OnInit(self):
frame = MainFrame(None, -1, "Hello from wxPython")
frame.Show(True)
self.SetTopWindow(frame)
return True
# Container window to hold a splitter window
class RootWindow(wx.Window):
def __init__(self, parent, id):
wx.Window.__init__(self, parent, id)
self.initpos = 200
#Create Splitter window
self.SplitWinRootV = wx.SplitterWindow(self, -1, size = (-1, -1))
#Add sub elements
self.SideWindow = Pnl1(self.SplitWinRootV)
self.MainWindow = Pnl2(self.SplitWinRootV)
#Split Vertically
self.SplitWinRootV.SplitVertically(self.SideWindow, self.MainWindow, self.initpos)
#Define two sub panels for the above splitter window
class Pnl1(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, -1, style=wx.SUNKEN_BORDER, size = (-1,-1))
st = wx.StaticText(self, -1,"panel 1 sdd",(50, 50))
box = wx.BoxSizer(wx.VERTICAL)
box.Add(st, 2, wx.EXPAND)
self.SetAutoLayout(True)
self.SetSizer(box)
self.Layout()
class Pnl2(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, -1, style=wx.SUNKEN_BORDER, size = (-1,-1))
st = wx.StaticText(self, -1,"You can put nearly any type of window here,\n",(50, 50))
box = wx.BoxSizer(wx.VERTICAL)
box.Add(st, 2, wx.EXPAND)
self.SetAutoLayout(True)
self.SetSizer(box)
self.Layout()
app = MainApp(0)
app.MainLoop()
#code Ends