我一直在尝试最终拥有一个使用简单矢量图像作为背景的应用程序,因此可以根据需要缩放和调整屏幕大小。我暂时一直在用光栅照片测试这个不幸的是,我是个菜鸟,虽然我了解了正在发生的事情的要点,但我没有足够的经验来为我自己的目的修改它。话虽如此,我如何在面板上保留背景图像并使用 wxpython 实时缩放图像与面板大小?我现在有一些拼凑的代码:import pathlibimport wxclass MainApp(wx.App): def __init__(self, redirect=False, filename=None): wx.App.__init__(self, redirect, filename) dlg = MainFrame(parent=None,title="IvyVine") dlg.Show()####################################class MainFrame(wx.Frame): def __init__(self, parent, title): wx.Frame.__init__(self, parent=None, title="IvyVine",size=(1000,500)) panel = MainPanel(self) self.Center() self.Show(True) def OnExit(self,e): self.Close(True) #Closes the frame####################################class MainPanel(wx.Panel): def __init__(self, parent): bg_img = 'window.JPG' wx.Panel.__init__(self, parent=parent) self.SetBackgroundStyle(wx.BG_STYLE_ERASE) self.frame = parent self.bg = wx.Bitmap(bg_img) self._width, self._height = self.bg.GetSize() sizer = wx.BoxSizer(wx.VERTICAL) hSizer = wx.BoxSizer(wx.HORIZONTAL) for num in range(3): 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_SIZE, self.OnSize) self.Bind(wx.EVT_PAINT, self.OnPaint) #--------------------------- def scale_bg(self, bitmap, width, height): pass #--------------------------- def OnSize(self, size): self.Layout() self.Refresh() #--------------------------- def OnPaint(self, evt): dc = wx.BufferedPaintDC(self) self.Draw(dc) #--------------------------- def Draw(self, dc): cliWidth, cliHeight = self.GetClientSize() if not cliWidth or not cliHeight: return dc.Clear()
添加回答
举报
0/150
提交
取消