我需要在具有背景图像的框架中显示带有圆边的按钮。该按钮带有圆形边缘,但我仍然看到按钮外面的矩形框架与背景图像重叠:
正如你所看到的那样,按钮边缘是白色的 - 无论我使用的是什么按钮类型都是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()
有没有办法可以摆脱按钮边缘的额外像素并使其完全看起来有圆角?