954,546 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

wxPython help please?

I'm relatively new to programming in wxPython and I have been trying to put a BoxSizer within a wx.Window. This only results in a small square (which is the panel within the BoxSizer) appearing in the window. Could somebody please tell me what I'm doing wrong?

Sample code:

<code>class TestPanel(wx.Frame):
    def __init__(self, parent, id):
        wx.Frame.__init__(self, parent, -1, size = (800, 400))
        
        win = wx.Window (self, -1)
        
        box = wx.BoxSizer(wx.VERTICAL)
        panel2 = wx.Panel(win)
        panel2.SetBackgroundColour(&quot;Red&quot;)
        box.Add(panel2, 1, wx.EXPAND, 10)
        self.SetSizer(box)</code>

Thanks in advance!

dreambreeze
Newbie Poster
1 post since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

Is this what you want ...

import wx

class TestPanel(wx.Frame):
    def __init__(self, parent, id):
        wx.Frame.__init__(self, parent, -1,
            'wx.BoxSizer test', size = (800, 400))

        #win = wx.Window (self, -1)

        box = wx.BoxSizer(wx.VERTICAL)
        panel1 = wx.Panel(self)
        panel1.SetBackgroundColour("green")
        # 1=stretch allowed, and use 10 pixel border
        box.Add(panel1, 1, wx.ALL|wx.EXPAND, 10)
        panel2 = wx.Panel(self)
        panel2.SetBackgroundColour("Red")
        box.Add(panel2, 1, wx.ALL|wx.EXPAND, 10)
        self.SetSizer(box)

        # show the frame
        self.Show(True)

app = wx.PySimpleApp()
tp = TestPanel(None, -1)
app.MainLoop()
vegaseat
DaniWeb's Hypocrite
Moderator
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You