fit image exactly to wx panel

Hi,
I am trying to display an image on a wx panel. I know what the image size is in pixels. I set the wxframe and wx panel size to exactly the size of my image. However when I run the script, I can see that the panel covers the image slightly. That means that most likely the panel does not have the exact same size as of the image. Anyone knows how I can fit the image exactly to the panel size ?

regards,

pluto

import wx

import os

class Panel(wx.Panel):

def __init__(self, parent, path):


    bitmap = wx.Bitmap(path)

    orgWidth = bitmap.GetWidth()

    orgHeight = bitmap.GetHeight()


    panelWidth = orgWidth

    panelHeight = orgHeight


    wx.Panel.__init__(self, parent,-1, size=(panelWidth, panelHeight))


    self.ImgControl = wx.StaticBitmap(self, -1, bitmap)

    self.ImgControl.Center( )

if name == ‘main’:

app = wx.PySimpleApp()

frame = wx.Frame(None, -1, 'Scaled Image', size=(1392, 1040))

panel = Panel(frame, os.path.join( os.getcwd(), "middleWhite.tif") )

frame.Show()

app.MainLoop()

Hi,
I am trying to display an image on a wx panel. I know what the image size is
in pixels. I set the wxframe and wx panel size to exactly the size of my
image. However when I run the script, I can see that the panel covers the
image slightly. That means that most likely the panel does not have the
exact same size as of the image. Anyone knows how I can fit the image
exactly to the panel size ?

regards,

pluto

import wx
import os

class Panel(wx.Panel):
    def __init__(self, parent, path):

        bitmap = wx.Bitmap(path)
        orgWidth = bitmap.GetWidth()
        orgHeight = bitmap.GetHeight()

        panelWidth = orgWidth
        panelHeight = orgHeight

        wx.Panel.__init__(self, parent,-1, size=(panelWidth, panelHeight))

        self.ImgControl = wx.StaticBitmap(self, -1, bitmap)
        self.ImgControl.Center( )

if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = wx.Frame(None, -1, 'Scaled Image', size=(1392, 1040))
    panel = Panel(frame, os.path.join( os.getcwd(), "middleWhite.tif") )
    frame.Show()
    app.MainLoop()

I find the best way to get a window to size to the content, is not to
specify the size explicitly but instead use the sizer.Fit method

import wx
import os

class Panel(wx.Panel):
    def __init__(self, parent, path):

        bitmap = wx.Bitmap(path)

        wx.Panel.__init__(self, parent)

        sizer = wx.BoxSizer()

        self.ImgControl = wx.StaticBitmap(self, -1, bitmap)
        sizer.Add(self.ImgControl, 1, wx.EXPAND)

        self.SetSizer(sizer)
        sizer.Fit(parent)

if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = wx.Frame(None, -1, 'Scaled Image')
    panel = Panel(frame, os.path.join( os.getcwd(), "middleWhite.tif") )
    frame.Show()
    app.MainLoop()

···

On 16 October 2014 19:11, pluto mars <plutomars955@gmail.com> wrote:

--
You received this message because you are subscribed to the Google Groups
"wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.