Hi guys!

Im new to this forum so go easy on me :-)

I've got a background in C programming and have recently moved to Python for a GUI project im working on. So far im loving it - compared to VC++ wxPython is pure bliss. Im having a slight problem though.

Im trying to arrange a few different panels within the same frame and its just not showing anything. I'm pretty sure the Direction & Title panels work individually - but they were drawing on top of each other so i want to be able to arrange them all individually (especially as i will be adding more panels eventually)

Im trying to pretty much teaching myself everything as i go so i may be missing something very obvious.

This is what ive got so far

import wx
 
ID_MENU_EXIT   = 101
ID_MENU_ABOUT  = 102
ID_RADIO_FORWARDS   = 201
ID_RADIO_STATIONARY = 202
ID_RADIO_BACKWARDS  = 203
 
 
class Frame1(wx.Frame): 
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, -1, title, pos=(150, 150), size=(640, 480))
 
### MENU ###
 
        # Create a menubar at the top of the frame
        MenuBar = wx.MenuBar()
        FileMenu = wx.Menu()
        HelpMenu = wx.Menu() 
        # Add items to the menu                
        FileMenu.Append(ID_MENU_EXIT, "E&xit\tAlt-F4", "Exit the program")
        HelpMenu.Append(ID_MENU_ABOUT, "&About", "About the program")
 
        # Bind the menu event to an event handler        
        self.Bind(wx.EVT_MENU, self.OnMenuExit, id=ID_MENU_EXIT)
        self.Bind(wx.EVT_MENU, self.OnMenuAbout, id=ID_MENU_ABOUT)
 
        # Put the menu on the menubar
        MenuBar.Append(FileMenu, "&File")
        MenuBar.Append(HelpMenu, "&Help")
        self.SetMenuBar(MenuBar)
 
### STATUS BAR ###
 
        # create a status bar at the bottom of the frame
        self.CreateStatusBar()
 
 
### TITLE PANEL ###
 
        Title_Panel = wx.Panel(self)
 
        Title_Label = wx.StaticText(Title_Panel, -1, "Sequence Driven Controller")
        Title_Label.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.BOLD, True))
        Title_Label.SetForegroundColour('#00009F')
 
        Title_Sizer = wx.BoxSizer(wx.VERTICAL)
        Title_Sizer.Add(Title_Label, 0, wx.ALL, 10)
 
        Title_Panel.SetSizer(Title_Sizer)
        Title_Panel.Layout()
 
### DIRECTION PANEL ###
 
        Direction_Panel = wx.Panel(self)
        RadioButtonForwards = wx.RadioButton(Direction_Panel, ID_RADIO_FORWARDS, "Forwards")
        RadioButtonStationary = wx.RadioButton(Direction_Panel, ID_RADIO_STATIONARY, "Stationary")
        RadioButtonBackwards = wx.RadioButton(Direction_Panel, ID_RADIO_BACKWARDS, "Backwards")
        Direction_Sizer = wx.BoxSizer(wx.HORIZONTAL)
        Direction_Sizer.Add(RadioButtonForwards, 0, wx.ALL, 10)
        Direction_Sizer.Add(RadioButtonStationary, 0, wx.ALL, 10)
        Direction_Sizer.Add(RadioButtonBackwards, 0, wx.ALL, 10)
 
        Direction_Panel.SetSizer(Direction_Sizer)
        Direction_Panel.Layout()
 
 
### MAIN SIZER CONTROL ###
 
        Main_Sizer = wx.BoxSizer(wx.VERTICAL)
        Main_Sizer.Add(Title_Sizer, 0, wx.ALL, 10)
        Main_Sizer.Add(Direction_Sizer, 0, wx.ALL, 10)
 
        self.SetSizer(Main_Sizer)
        Main_Sizer.Layout()
 
 
### MENU EVENTS ###
 
    def OnMenuExit(self, evt):
        self.Close()
 
    def OnMenuAbout(self, evt):
        dlg = wx.MessageDialog(self, "Sequence Driven Controller\n"
                              "Mark Walker 2006/07\n"
                              "Final Year Engineering Project", "Sequence Driven Controller",
                               wx.OK | wx.ICON_INFORMATION)
        dlg.ShowModal()
        dlg.Destroy()
 
 
 
class wxPyApp(wx.App):
    def OnInit(self):
        frame = Frame1(None, "Sequence Driven Controller")
        self.SetTopWindow(frame)
        frame.Show(True)
        return True
 
app = wxPyApp(redirect=True)
app.MainLoop()

Any help would be greatly appreciated


Mark

In MAIN SIZER CONTROL don't add the sizer to a sizer, but the panel:

import wx
 
ID_MENU_EXIT   = 101
ID_MENU_ABOUT  = 102
ID_RADIO_FORWARDS   = 201
ID_RADIO_STATIONARY = 202
ID_RADIO_BACKWARDS  = 203
 
 
class Frame1(wx.Frame): 
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, -1, title, pos=(150, 150), size=(640, 480))
 
### MENU ###
 
        # Create a menubar at the top of the frame
        MenuBar = wx.MenuBar()
        FileMenu = wx.Menu()
        HelpMenu = wx.Menu() 
        # Add items to the menu                
        FileMenu.Append(ID_MENU_EXIT, "E&xit\tAlt-F4", "Exit the program")
        HelpMenu.Append(ID_MENU_ABOUT, "&About", "About the program")
 
        # Bind the menu event to an event handler        
        self.Bind(wx.EVT_MENU, self.OnMenuExit, id=ID_MENU_EXIT)
        self.Bind(wx.EVT_MENU, self.OnMenuAbout, id=ID_MENU_ABOUT)
 
        # Put the menu on the menubar
        MenuBar.Append(FileMenu, "&File")
        MenuBar.Append(HelpMenu, "&Help")
        self.SetMenuBar(MenuBar)
 
### STATUS BAR ###
 
        # create a status bar at the bottom of the frame
        self.CreateStatusBar()
 
 
### TITLE PANEL ###
 
        Title_Panel = wx.Panel(self)
 
        Title_Label = wx.StaticText(Title_Panel, -1, "Sequence Driven Controller")
        Title_Label.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.BOLD, True))
        Title_Label.SetForegroundColour('#00009F')
 
        Title_Sizer = wx.BoxSizer(wx.VERTICAL)
        Title_Sizer.Add(Title_Label, 0, wx.ALL, 10)
 
        Title_Panel.SetSizer(Title_Sizer)
        Title_Panel.Layout()
 
### DIRECTION PANEL ###
 
        Direction_Panel = wx.Panel(self)
        RadioButtonForwards = wx.RadioButton(Direction_Panel, ID_RADIO_FORWARDS, "Forwards")
        RadioButtonStationary = wx.RadioButton(Direction_Panel, ID_RADIO_STATIONARY, "Stationary")
        RadioButtonBackwards = wx.RadioButton(Direction_Panel, ID_RADIO_BACKWARDS, "Backwards")
        Direction_Sizer = wx.BoxSizer(wx.HORIZONTAL)
        Direction_Sizer.Add(RadioButtonForwards, 0, wx.ALL, 10)
        Direction_Sizer.Add(RadioButtonStationary, 0, wx.ALL, 10)
        Direction_Sizer.Add(RadioButtonBackwards, 0, wx.ALL, 10)
 
        Direction_Panel.SetSizer(Direction_Sizer)
        Direction_Panel.Layout()
 
 
### MAIN SIZER CONTROL ###
        
        Main_Sizer = wx.BoxSizer(wx.VERTICAL)
        #Main_Sizer.Add(Title_Sizer, 0, wx.ALL, 10)  # don't add the sizer but the panel
        Main_Sizer.Add(Title_Panel, 0, wx.ALL, 10)
        #Main_Sizer.Add(Direction_Sizer, 0, wx.ALL, 10)  # don't add the sizer but the panel
        Main_Sizer.Add(Direction_Panel, 0, wx.ALL, 10)
 
        self.SetSizer(Main_Sizer)
        Main_Sizer.Layout()
        
 
### MENU EVENTS ###
 
    def OnMenuExit(self, evt):
        self.Close()
 
    def OnMenuAbout(self, evt):
        dlg = wx.MessageDialog(self, "Sequence Driven Controller\n"
                              "Mark Walker 2006/07\n"
                              "Final Year Engineering Project", "Sequence Driven Controller",
                               wx.OK | wx.ICON_INFORMATION)
        dlg.ShowModal()
        dlg.Destroy()
 
 
 
class wxPyApp(wx.App):
    def OnInit(self):
        frame = Frame1(None, "Sequence Driven Controller")
        self.SetTopWindow(frame)
        frame.Show(True)
        return True
 
app = wxPyApp(redirect=True)
app.MainLoop()

Welcome to the forum!

Bingo!


Many thanks (for the welcome & the answer) :-)


Mark

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.