newbie : colour for a wx.Panel with defined size fills entire containing wx.Frame

Hi I am trying to have a wx.frame of a particular size and within it a
region that is coloured a separate background color using wx.Panel.

I am using the following code ( see below ) and running it on a Mac
as well
as in Ubuntu Linux. My Problem is that the wx.Panel element always
fills the
entire wx.Frame object. So instead of having a blue box (wx.Panel)
inside a
grey wx.Frame. The entire frame is blue. I dont know what I doing
wrong. I
did look at this example <http://wiki.wxpython.org/AnotherTutorial> ,
and so
I know it can be done . But the example uses grid-sizers and a
wx.Dialog
unlike my simpler case.

Here is my code that currently gnerates a blue square frame of size
300 instead of a frame which is gray with a small blue box.
Any help will be greatly appreciated

import wx

class PlateGui(wx.Frame):

    def __init__(self, *args , **kwds):
        self.frame = wx.Frame.__init__(self,*args, **kwds)
        print "Made frame"

if __name__ == "__main__":
    an_app = wx.PySimpleApp()
    aframe = PlateGui(parent=None,id=-1,title="Test Frame",size=(300,
300))
    pane = wx.Panel(parent=aframe,id=-1,size=(10,10))
    pane.SetBackgroundColour(wx.Colour(0,0,255))
    aframe.Show()
    an_app.MainLoop()
    print "Hello World"

Thanks

hari

Hello,

Hi I am trying to have a wx.frame of a particular size and within it a
region that is coloured a separate background color using wx.Panel.

I am using the following code ( see below ) and running it on a Mac
as well
as in Ubuntu Linux. My Problem is that the wx.Panel element always
fills the
entire wx.Frame object. So instead of having a blue box (wx.Panel)
inside a
grey wx.Frame. The entire frame is blue. I dont know what I doing
wrong. I
did look at this example <http://wiki.wxpython.org/AnotherTutorial&gt; ,
and so
I know it can be done . But the example uses grid-sizers and a
wx.Dialog
unlike my simpler case.

Here is my code that currently gnerates a blue square frame of size
300 instead of a frame which is gray with a small blue box.
Any help will be greatly appreciated

You should always place one main panel as the child of the Frame and
then any sub-panels (i.e your blue one) as a child of that main panel.

For example your modified sample code:

import wx

class PlateGui(wx.Frame):

   def __init__(self, *args , **kwds):
        self.frame = wx.Frame.__init__(self,*args, **kwds)

        # Attributes
        self._panel = MainPanel(self)

class MainPanel(wx.Panel):
    def __init__(self, *args, **kwds):
        wx.Panel.__init__(self, *args, **kwds)

        # Attributes
        self._bpanel = wx.Panel(self, id=wx.ID_ANY, size=(10,10))
        self._bpanel.SetBackgroundColour(wx.Colour(0,0,255))

        # Layout
        vsizer = wx.BoxSizer(wx.VERTICAL)
        hsizer = wx.BoxSizer(wx.HORIZONTAL)
        hsizer.Add(self._bpanel, 0, wx.ALIGN_CENTER)
        vsizer.AddStretchSpacer()
        vsizer.Add(hsizer, 0, wx.ALIGN_CENTER)
        vsizer.AddStretchSpacer()
        self.SetSizer(vsizer)
        self.SetAutoLayout(True)

if __name__ == "__main__":
   an_app = wx.PySimpleApp()
   aframe = PlateGui(parent=None, id=wx.ID_ANY,
                     title="Test Frame", size=(300, 300))
   aframe.Show()
   an_app.MainLoop()
   print "Hello World"

Cody

···

On Wed, Jun 24, 2009 at 5:27 AM, harijay<harijay@gmail.com> wrote: