Given
panel = wx.Panel(self,-1)
bmp = wx.Image(imageFile, wx.BITMAP_TYPE_BMP).ConvertToBitmap()
\# Now Display the bmp on the panel
\# without clicking, resizing or shrinking the window
\#
\# \.\.\.\.but how? ??
The easy way is to add a wx.StaticBitmap control to fill the panel, and call SetBitmap to assign the bitmap to that control. It will do everything necessary to display the image.
If you really, really want to do it yourself, you'll need to catch the EVT_PAINT message and use wx.DC.DrawBitmap.
···
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
You created a new panel, and did not give it a size, so it probably defaulted to a small size like (20,20). It doesn’t matter that the bitmap button is sized to (600,400), if its parent is not at least that big then it will be clipped to the size of the parent. When you resize the window it triggers the default EVT_SIZE handlers, which in the case of wx.Frame (which is what I assume self is above) will check if it has only one child (like the panel) and will then resize and reposition it to fill the client area of the frame.
A better approach would be to create all the widgets (the frame, panel, static bitmap, and whatever else you need, like maybe a button or menu to trigger opening the file dialog, etc.) at the start, as part of the frame’s init method. Then later when you get the desired image filename from the user all you need to do is create the bitmap and do something like
self.static_bmp.SetBitmap(theBitmap)
···
On Wednesday, June 5, 2019 at 4:17:35 PM UTC-7, srfpala wrote:
I’m trying to figure out why the code below isn’t working.
You aren't using any sizers, so your StaticBitmap is not going to resize itself automatically. Create a wx.BoxSizer(wx.HORIZONTAL), attach it to the panel, and add the StaticBitmap to it.
···
On Jun 9, 2019, at 2:29 PM, srfpala <srfpala@gmail.com> wrote:
Well, I would like to remove the button and place the image on the panel.
—
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.