Hey all,
I’m new to wxPython, so there’s no real functionality in this example - I’m just trying to get my bearings, but I essentially want:
2x Panels, children of the main Frame
Panel 1 paints 3 circles
Panel 2 has 2 Text widgets
However, when I add in the Bind for the painting panel, my second panel disappears. I’m mystified how one is affecting the other. Can anyone point me in the right direction?
class Drawing_Panel(wx.Panel):
def __init__(self, *args, **kwargs):
wx.Panel.__init__(self, *args, **kwargs)
self.SetBackgroundColour(wx.RED)
self.SetSize(640,480)
self.Bind(wx.EVT_PAINT, self.OnPaint) #Commenting out this line makes the panels display.
def OnPaint(self, event):
self.dc = wx.PaintDC(self)
self.dc.SetPen(wx.Pen('WHITE'))
self.w, self.h = self.GetClientSize()
self.circle1 = self.dc.DrawCircle(24, 42, 10)
self.circle2 = self.dc.DrawCircle(247, 17, 10)
self.circle3 = self.dc.DrawCircle(75, 117, 10)
class Info_Panel(wx.Panel):
def __init__(self, *args, **kwargs):
wx.Panel.__init__(self, *args, **kwargs)
self.SetBackgroundColour(wx.WHITE)
self.vertical_sizer = wx.BoxSizer(wx.VERTICAL)
self.st_text_widget1 = wx.StaticText(self, label='This is a Test')
self.st_text_widget2 = wx.StaticText(self, label='This is also a test')
self.vertical_sizer.Add(self.st_text_widget1, 0, wx.EXPAND)
self.vertical_sizer.Add(self.st_text_widget2, 0, wx.EXPAND)
self.SetSizer(self.vertical_sizer)
self.SetSize(640,480)
class Main_Frame(wx.Frame):
def __init__(self, *args, **kw):
wx.Frame.__init__(self, *args, **kw)
self.InitUI()
def InitUI(self):
self.SetTitle("Test Window Program")
self.Centre()
self.drawing_panel = Drawing_Panel(self)
self.main_information_panel = Info_Panel(self)
self.main_ui_grid_sizer = wx.GridBagSizer(vgap = 0, hgap = 0)
self.main_ui_grid_sizer.Add(self.drawing_panel, pos=(0,0), flag=wx.EXPAND)
self.main_ui_grid_sizer.Add(self.main_information_panel, pos=(0,1), flag=wx.EXPAND)
self.main_ui_grid_sizer.AddGrowableRow(0, 0)
self.main_ui_grid_sizer.AddGrowableCol(0, 0)
self.main_ui_grid_sizer.AddGrowableCol(1, 0)
self.SetSizer(self.main_ui_grid_sizer)
self.SetSize(640*2,480*2)
def main():
app = wx.App()
main_frame = Main_Frame(None)
main_frame.Show()
app.MainLoop()
if __name__ == '__main__':
main()
Any help would be very appreciated. Thanks!