import wx
class TransparentText(wx.StaticText):

    def __init__(self, parent, id=wx.ID_ANY, label='12231', pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.TRANSPARENT_WINDOW, name='transparenttext'):

        wx.StaticText.__init__(self, parent, id, label, pos, size, style, name)
        self.SetBackgroundColour('blue')

        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()


def main():

    app = wx.App()
    ex = wx.Frame(None)
    TransparentText(parent=ex)
    ex.Show()
    app.MainLoop()


if __name__ == '__main__':
    main()

参考于
 参考于:http://www.itkeyword.com/doc/6413126069974283x677/wxpython-Transparent-statictext 

发表评论

电子邮件地址不会被公开。 必填项已用*标注