新人求助:wxpython在带有背景图的框架上显示静态文本

回锅肉盖浇面 2019-04-22 10:43:09

运行结果中的静态文本背景色我设为了蓝色,我希望不显示其背景色(也不是默认的白色),希望有大神解答,非常感谢

class MyPanel(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id)
try:
image_file = 'background.jpg'
to_bmp_image = wx.Image(image_file, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
self.bitmap = wx.StaticBitmap(self, -1, to_bmp_image, (0, 0))
image_width = to_bmp_image.GetWidth()
image_height = to_bmp_image.GetHeight()
set_title = '%s %d x %d' % (image_file, to_bmp_image.GetWidth(), to_bmp_image.GetHeight())
parent.SetTitle(set_title)
except IOError:
print('Image file %s not found' % image_file)
raise SystemExit
#创建一个按钮
self.button = wx.Button(self.bitmap, -1, label='Test', pos=(10,10))
st_tips = wx.StaticText(self ,0,u"sspu 停车管理系统",pos=(10,50))
st_tips.SetForegroundColour('white')
st_tips.SetBackgroundColour('blue')
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = wx.Frame(None, -1, 'Image', size=(300,300))
my_panel = MyPanel(frame, -1)
frame.Show()
app.MainLoop()
...全文
208 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
我也碰到过这个问题,后来在网上找到了答案:

#transparent_txt.py

import wx


class TransparentText(wx.StaticText):
def __init__(self, parent, id=wx.ID_ANY, label='', pos=wx.Default Position,
size=wx.DefaultSize, style=wx.TRANSPARENT_WINDOW, na me=''):
wx.StaticText.__init__(self, parent, id, label, pos, size, style, na me)

self.Bind(wx.EVT_PAINT, self.on_paint)
self.Bind(wx.EVT_ERASE_BACKGROUND, lambda event: None )
self.Bind(wx.EVT_SIZE, self.on_size)

def on_paint(self, event):
bdc = wx.PaintDC(self)
dc = wx.GCDC(bdc)

font_face = self.GetFont()
font_color = self.GetForegroundColour()

dc.SetFont(font_face)
dc.SetTextForeground(font_color)
dc.DrawText(self.GetLabel(), 0, 0)

def on_size(self, event):
self.Refresh()
event.Skip()

37,720

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧