开发者

building gui using wxpython

开发者 https://www.devze.com 2023-04-05 11:20 出处:网络
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 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'
      开发者_JAVA技巧  bmp = wx.Bitmap(img)
        btmap = wx.StaticBitmap(panel, wx.ID_ANY, bmp, (0, 0))  


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消