import wx
class MyPanel(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1)
self.SetBackgroundStyle(wx.BG_STYLE_ERASE )
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
self.Bind(wx.EVT_SIZE,self.onSize)
self.bg_img=wx.Image("images/bg.gif")
def OnEraseBackground(self, evt):
dc = evt.GetDC()
if not dc:
dc = wx.ClientDC(self)
rect = self.GetUpdateRegion().GetBox()
dc.SetClippingRect(rect)
dc.Clear()
self.StretchBackground(dc)
def StretchBackground(self, dc):
sz = self.GetClientSize()
image = self.bg_img.Scale(sz.x,sz.y)
bg_bmp = image.ConvertToBitmap()
dc.DrawBitmap(bg_bmp, 0, 0)
def onSize(self,evt):
self.Refresh()
# evt.Skip()
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = MyPanel()
frame.Show()
app.MainLoop()
自适应的背景图片
最新推荐文章于 2021-07-15 10:14:35 发布