0

I added an image into a panel in my gui . I want this image to be fitted in the panel, where i wanna make its length as same as the panel legth .. How can i do this please ?

i did the following in my code ? so the image appeared at the top of the panel as what i want, but i wanna resize this image to increase its length .

 class myMenu(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(900, 700))
        panel = wx.Panel(self, -1)
        panel.SetBackgroundColour('#4f3856')
        img = 'C:\Users\DELL\Desktop\Implementation\img1.jpg'
        bmp = wx.Bitmap(img)
        btmap = wx.StaticBitmap(panel, wx.ID_ANY, bmp, (0, 0))  
1
  • You created wx.StaticBitmap with a position but not a size. Just pass the size you want. Commented Sep 14, 2011 at 21:31

1 Answer 1

1

If you want to scale the image you'll probably want to open it as a wx.Image rather than a wx.Bitmap. You can then scale it using the wx.Image's scale(self, width, height, quality) method http://www.wxpython.org/docs/api/wx.Image-class.html#Scale

The real problem is you want to get the image to resize every time the window does. That means you'll need to bind the wx.EVT_SIZE event to some method in your class (say onSize). Then every time onSize is called, you'll need to:

  1. Find the current window size,
  2. Scale the wx.Image to that size,
  3. Convert it to a wx.Bitmap using wx.BitmapFromImage,
  4. Call SetBitmap on your wx.StaticBitmap, passing the new bitmap.

See http://zetcode.com/wxpython/events/ for a basic introduction to event handling in wxPython, including an example with the wx.EVT_SIZE.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.