I have MyPanel
of size (1200,800) which is embedded in a parent MainPanel
(whose size can change with the size of the MainFrame
) :
import wx
class MyPanel(wx.Panel): # panel embedded in the main panel
def __init__(self, parent):
wx.Panel.__init__(self, parent, -1, size=(1200,800))
sizer = wx.BoxSizer(wx.VERTICAL)
bmp = wx.BitmapFromImage(wx.Image('background.png', wx.BITMAP_TYPE_PNG))
myimg = wx.StaticBitmap(self, -1, bmp)
sizer.Add(myimg, 0, wx.SHAPED, 10)
class MainPanel(wx.Panel): # main panel embedded in the main frame
def __init__(self, parent):
wx.Panel.__init__(self, parent, -1)
self.mypanel = MyPanel(self)
class MainFrame(wx.Frame): # main frame window
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, -1, title, size=(800,600))
self.panel = MainPanel(self)
self.Show()
app = wx.App(0)
frame = MainFrame(None, 'Test')
app.MainLoop()
How is it possible to automatically rescale MyPanel
so that it fits in the parent MainPanel
, keeping its aspect ratio ?
Remark : I am looking for a behaviour close to Windows's standard photo viewer : when the window is resized, the image is rescaled to fit in the parent window.