wxPython用于图像和按钮(可调整大小)

wxPython用于图像和按钮(可调整大小),第1张

wxPython用于图像按钮(可调整大小)

我用以下方法解决了问题:

import wxfrom floatcanvas import FloatCanvasclass MyPanel(wx.Panel):    def __init__(self, parent):        super(MyPanel, self).__init__(parent)        self.sizer = wx.BoxSizer(wx.VERTICAL)        self.SetSizer(self.sizer)        # add a canvas        self.Canvas = FloatCanvas.FloatCanvas(self, BackgroundColor = "LIGHT GREY")        self.Canvas.Bind(wx.EVT_SIZE, self.OnSize)        self.sizer.Add(self.Canvas, -1, flag=wx.EXPAND)        # add a toggle button        image_dis = wx.Image('file_disabled.png')        image_ena = wx.Image('file_enabled.png')        img_dis = self.Canvas.AddScaledBitmap(image_dis, (x,-y), Height=image_dis.GetHeight(), Position = 'tl')        img_ena = self.Canvas.AddScaledBitmap(image_ena, (x,-y), Height=image_ena.GetHeight(), Position = 'tl')        img_dis.other = img_ena        img_ena.other = img_dis        img_ena.Visible = False        # bind the toggle button event         img_dis.Bind(FloatCanvas.EVT_FC_LEFT_UP, self.OnToggle)        img_ena.Bind(FloatCanvas.EVT_FC_LEFT_UP, self.OnToggle)    def onToggle(self, button):        button.other.Visible = True        button.Visible = False        self.Canvas.Draw(True)    def onSize(self, event):        event.Skip()        wx.CallLater(1, self.Canvas.ZoomToBB)


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5617741.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存