我用以下方法解决了问题:
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)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)