title: wxpython:How can I get the size of a panel or let a image fit the size of panel
body: <p>I want to put an image into the center of a wxPanel, I am considering that I need to resize the image to fit the wxPanel. But I can't get the size of a wxPanel  dynamically. And here is a test code.</p>
  
  <pre><code>#!/usr/bin/python
  
  # wxboxsizer.py
  
  import wx
  
  class MyFrame(wx.Frame):
      def __init__(self, parent, id, title):
          wx.Frame.__init__(self, parent, id, title, (-1, -1), wx.Size(500, 500))
          panel1 = wx.Panel(self, -1,style= wx.SIMPLE_BORDER)
          panel2 = wx.Panel(self, -1,style= wx.SIMPLE_BORDER)
          panel3 = wx.Panel(self, -1,style= wx.SIMPLE_BORDER)
          box = wx.BoxSizer(wx.VERTICAL)
          box.Add(panel1, 1,flag = wx.EXPAND|wx.ALL,border = 3 )
          box.Add(panel2, 1,flag = wx.EXPAND|wx.ALL,border = 3 )
          box.Add(panel3, 1,flag = wx.EXPAND |wx.ALL,border = 3)
          self.SetSizer(box)
  
  
  class MyApp(wx.App):
      def OnInit(self):
          frame = MyFrame(None, -1, 'wxboxsizer.py')
          frame.Show(True)
          return True
  
  app = MyApp(0)
  app.MainLoop()
  </code></pre>
  
  <p>This code can let the 3 panels fit the frame perfectly, but how can I get the size of the panel dynamically.
  Furthermore, how can I put an image into a panel, and let the image fit the panel dynamically?</p>
  
  <p><strong>My solution:</strong> I just got a method to get the size of panel when the frame is resized.</p>
  
  <pre><code>#!/usr/bin/python
  
  # wxboxsizer.py
  
  import wx,os
  
  class MyFrame(wx.Frame):
      def __init__(self, parent, id, title):
          wx.Frame.__init__(self, parent, id, title, (-1, -1), wx.Size(500, 500))
          self.panel1 = wx.Panel(self, -1,style= wx.SIMPLE_BORDER)
          panel2 = wx.Panel(self, -1,style= wx.SIMPLE_BORDER)
          panel3 = wx.Panel(self, -1,style= wx.SIMPLE_BORDER)
          box = wx.BoxSizer(wx.VERTICAL)
          box.Add(self.panel1, 1,flag = wx.EXPAND|wx.ALL,border = 3 )
          box.Add(panel2, 1,flag = wx.EXPAND|wx.ALL,border = 3 )
          box.Add(panel3, 1,flag = wx.EXPAND |wx.ALL,border = 3)
          self.Bind(wx.EVT_SIZE, self.OnSize)
          self.SetSizer(box)
  
      def OnSize(self, event):
          size = self.GetSize()
          size2 = self.panel1.GetSize()
          print size,size2
          event.Skip()
  
  
  class MyApp(wx.App):
      def OnInit(self):
          frame = MyFrame(None, -1, 'wxboxsizer.py')
          frame.Show(True)
          return True
  
  app = MyApp(0)
  app.MainLoop()
  </code></pre>
  
  <p>This code can show the size of panel when the frame is resized.</p>