Discussion:
fit image on wxpanel
pluto mars
2014-10-16 18:25:40 UTC
Permalink
Hi,

I want to display an image such that it fits exactly on a wxpanel. For this
I set the size of the wxpanel to the size of the image I want to display.
However I see that the panel is slightly smaller than my image. Anyone
knows how to solve this ?

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()
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Nathan McCorkle
2014-10-16 19:23:27 UTC
Permalink
You should use StaticBitmap for icons, while GenStaticBitmap should be used
for images:
from wx.lib import statbmp
self.ImgControl = statbmp.GenStaticBitmap(self.panel, wx.ID_ANY, bitmap)

Not sure why the Panel is smaller, but it might have something to do with
the ClientSize vs Size... not sure. It might help if you use sizers, so
there you give the 'automagic' resizing info to work on. Resizing the frame
won't resize the image though, if that's what you want... you will need to
catch the Frame resize event then manually scale the image based on the new
size, then get a new scaled bitmap, then update/set the bitmap to the image
control. You probably also don't want to any of what I just said unless the
left mouse button is up (so as you drag the Frame to resize, it won't
generate a new scaled image for each pixel of Frame size that changes...
rather, for each resize event that fires, only the last one).
Post by pluto mars
Hi,
I want to display an image such that it fits exactly on a wxpanel. For
this I set the size of the wxpanel to the size of the image I want to
display. However I see that the panel is slightly smaller than my image.
Anyone knows how to solve this ?
regards,
Pluto
import wx
import os
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( )
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()
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Robin Dunn
2014-10-17 02:18:14 UTC
Permalink
Post by pluto mars
Hi,
I want to display an image such that it fits exactly on a wxpanel. For
this I set the size of the wxpanel to the size of the image I want to
display. However I see that the panel is slightly smaller than my image.
Anyone knows how to solve this ?
frame = wx.Frame(None, -1, 'Scaled Image', size=(1392, 1040))
panel = Panel(frame, os.path.join( os.getcwd(), "middleWhite.tif") )
Does the size of the image happen to be 1392x1040? If so then you are
setting the total size of the frame to that size, including the borders
and caption bar, so it is going to clip the panel. As Nathan mentioned,
the best way to do it is to use sizers to manage the size of windows
based on the needs of their children, although in this case you could
just do something like this before the Show:

frame.SetClientSize(panel.GetSize())

The client size for the frame is the area inside the borders.
--
Robin Dunn
Software Craftsman
http://wxPython.org
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Stephane Coint-bavarot
2014-10-18 04:48:20 UTC
Permalink
Hi pluto,

You force a size of your frame "size=(1392, 1040)", may be your image is
bigger than that.
I alway use a sizer with a panel even there is only one child and then add
the child to take full size.

I hope it could help.

Regards

Stephan
Post by pluto mars
Hi,
I want to display an image such that it fits exactly on a wxpanel. For
this I set the size of the wxpanel to the size of the image I want to
display. However I see that the panel is slightly smaller than my image.
Anyone knows how to solve this ?
regards,
Pluto
import wx
import os
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( )
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()
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...