为sizer wxpython设置拉伸背景图像?

为sizer wxpython设置拉伸背景图像?,python,wxpython,Python,Wxpython,我想知道如何用wxpython将拉伸的背景图像放在一个尺寸器中 我正在看本教程: 但图像不会调整大小 import wx ######################################################################## class MainPanel(wx.Panel): """""" #----------------------------------------------------------------------

我想知道如何用wxpython将拉伸的背景图像放在一个尺寸器中

我正在看本教程:

但图像不会调整大小

import wx

########################################################################
class MainPanel(wx.Panel):
    """"""

    #----------------------------------------------------------------------
    def __init__(self, parent):
        """Constructor"""
        wx.Panel.__init__(self, parent=parent)
        self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
        self.frame = parent

        sizer = wx.BoxSizer(wx.VERTICAL)
        hSizer = wx.BoxSizer(wx.HORIZONTAL)

        for num in range(4):
            label = "Button %s" % num
            btn = wx.Button(self, label=label)
            sizer.Add(btn, 0, wx.ALL, 5)
        hSizer.Add((1,1), 1, wx.EXPAND)
        hSizer.Add(sizer, 0, wx.TOP, 100)
        hSizer.Add((1,1), 0, wx.ALL, 75)
        self.SetSizer(hSizer)
        self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)

    #----------------------------------------------------------------------
    def OnEraseBackground(self, evt):
        """
        Add a picture to the background
        """
        # yanked from ColourDB.py
        dc = evt.GetDC()

        if not dc:
            dc = wx.ClientDC(self)
            rect = self.GetUpdateRegion().GetBox()
            dc.SetClippingRect(rect)
        dc.Clear()
        bmp = wx.Bitmap("Untitled.png")
        dc.DrawBitmap(bmp, 0, 0)


########################################################################
class MainFrame(wx.Frame):
    """"""

    #----------------------------------------------------------------------
    def __init__(self):
        """Constructor"""
        wx.Frame.__init__(self, None, size=(600,450))
        panel = MainPanel(self)
        self.Center()

########################################################################
class Main(wx.App):
    """"""

    #----------------------------------------------------------------------
    def __init__(self, redirect=False, filename=None):
        """Constructor"""
        wx.App.__init__(self, redirect, filename)
        dlg = MainFrame()
        dlg.Show()

#----------------------------------------------------------------------
if __name__ == "__main__":
    app = Main()
    app.MainLoop()
这就是代码,我不确定wxpython是否可以调整大小。所以基本上我只想用一张图片作为一个尺寸测量仪的背景,但是把图片拉伸到尺寸测量仪的大小


谢谢

这篇文章并不是为了展示如何拉伸或调整图像大小。为此,您可能需要Python映像库(PIL)。然后在调整大小时,可以获取帧的新大小,并使用该大小计算如何缩放图像。请参阅以下链接下载PIL:

这篇文章不是为了展示如何拉伸或调整图像大小。为此,您可能需要Python映像库(PIL)。然后在调整大小时,可以获取帧的新大小,并使用该大小计算如何缩放图像。请参阅以下链接下载PIL: