我需要在具有背景图像的框架中显示一个带有圆形边缘的按钮。该按钮带有圆角边缘,但我仍然看到按钮外的矩形框与背景图像重叠:
如您所见,按钮边缘呈白色 - 无论我使用 wxPython 提供的任何按钮类型。我也不能删除背景图像,因为它需要在那里:
#!/usr/bin/python
import wx
import wx.lib.agw.gradientbutton as GB
import wx.lib.platebtn as platebtn
class MainPanel(wx.Frame):
def __init__(self):
super(MainPanel, self).__init__(None, title='Medical App', size=(800, 480))
self.image = 'image0.png'
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.hSizer = wx.BoxSizer(wx.HORIZONTAL)
self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
self.chopbmp = wx.Bitmap("images1.png",wx.BITMAP_TYPE_PNG)
self.statbmp = wx.Bitmap("images2.png", wx.BITMAP_TYPE_PNG)
self.backbmp = wx.Bitmap("images3.png", wx.BITMAP_TYPE_PNG)
self.chopBtn = GB.GradientButton(self, bitmap=self.chopbmp, size=(410, 90))
#self.chopBtn = platebtn.PlateButton(self, label="Press Me", style=platebtn.PB_STYLE_NOBG)
#self.chopBtn = wx.BitmapButton(self, bitmap=self.chopbmp, size=(410, 90))
self.statBtn = GB.GradientButton(self, bitmap=self.statbmp, size=(410, 90))
self.backBtn = GB.GradientButton(self, bitmap=self.backbmp, size=(207,90))
#self.backBtn = wx.BitmapButton(self, bitmap=self.backbmp, size = (150, 50))
self.backBtn.Bind(wx.EVT_LEFT_DCLICK, self.buttonClick)
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
self.sizer.Add(self.chopBtn, 0, wx.ALL | wx.ALIGN_RIGHT, 0)
self.sizer.Add(self.statBtn, 0, wx.ALL | wx.ALIGN_RIGHT, 5)
self.sizer.Add(self.backBtn, 0, wx.ALL | wx.ALIGN_RIGHT, 5)
self.hSizer.Add((1,1), 5, wx.EXPAND)
self.hSizer.Add(self.sizer, 0, wx.TOP, 150)
self.hSizer.Add((1,1), 0, wx.ALL, 5)
self.SetSizer(self.hSizer)
self.SetPosition(wx.Point(0,0))
self.ShowFullScreen(True)
def buttonClick(self, evt):
self.Destroy()
def OnEraseBackground(self, evt):
dc = evt.GetDC()
if not dc:
dc = wx.ClientDC(self)
rect = self.GetUpdateRegion().GetBox()
dc.SetClippingRect(rect)
dc.Clear()
self.bg = wx.Image(self.image, wx.BITMAP_TYPE_PNG).ConvertToBitmap()
dc.DrawBitmap(self.bg, 0, 0)
if __name__ == "__main__":
application = wx.App()
MainPanel()
application.MainLoop()
有没有办法可以摆脱按钮边缘出现的这些额外像素,并使其看起来完全具有圆形边缘?