Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在wxpython中使wx.statictext文本透明_Python_Wxpython - Fatal编程技术网

如何在wxpython中使wx.statictext文本透明

如何在wxpython中使wx.statictext文本透明,python,wxpython,Python,Wxpython,我将文字字母透明地放在背景后面。问题是,如果自动更新,透明部分会像附加的图片一样消失 使用wx.CallLater的结果是相同的。我的代码有问题吗? 我不知道为什么。覆盖现象?您的代码似乎没有问题。它在Linux上工作。问题一定是wx和你的操作系统。谢谢你每次。当我在Linux上测试它时,类TransparentText(wx.StaticText):我没有使用它就得到了透明文本。为什么它在Windows上不同?根据szBackend设置来表达它有什么不同吗?没有后端只与“播放”媒体的方法有关。

我将文字字母透明地放在背景后面。问题是,如果自动更新,透明部分会像附加的图片一样消失

使用
wx.CallLater
的结果是相同的。我的代码有问题吗?
我不知道为什么。覆盖现象?

您的代码似乎没有问题。它在Linux上工作。问题一定是wx和你的操作系统。谢谢你每次。当我在Linux上测试它时,
类TransparentText(wx.StaticText):
我没有使用它就得到了透明文本。为什么它在Windows上不同?根据
szBackend
设置来表达它有什么不同吗?没有后端只与“播放”媒体的方法有关。这个问题与显示器有关。我发现,有时候,在Linux上,用于显示的主题会影响事物的外观和操作。例如,使用theme Mint-X将不允许使用彩色按钮,但其他主题则允许。我一直不知道为什么。这与操作系统上的本机小部件有关。一些操作系统允许其本机窗口小部件透明,而其他操作系统则不允许。wxPython使用本机小部件。如果您想做一些不同的事情,那么您将需要使用一个定制的小部件或切换到绘制其所有小部件的东西,如Tkinter或PyQt。
# -*- coding: utf-8 -*-
import wx, wx.media
import sqlite3
import os
import time

class MainFream(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None)
        self.leftPanel = wx.Panel(self, size=(0,0))
        self.media = wx.media.MediaCtrl(self,
                                        #szBackend=wx.media.MEDIABACKEND_GSTREAMER,
                                        szBackend=wx.media.MEDIABACKEND_WMP10,
                                        size = (0,0),
                                        style = wx.SIMPLE_BORDER)
        image = wx.Image('1.bmp', wx.BITMAP_TYPE_BMP).ConvertToBitmap()
        self.background = wx.StaticBitmap(self.leftPanel, 0, image, (0,0))


        self.hBoxSizer = wx.BoxSizer(wx.HORIZONTAL)
        self.hBoxSizer.Add(self.leftPanel, 1, wx.ALL|wx.EXPAND, 5)
        self.hBoxSizer.Add(self.media, 1, wx.ALL|wx.EXPAND, 5)
        self.SetSizer(self.hBoxSizer)

        self.conn = sqlite3.connect("test.db")
        self.cursor = self.conn.cursor()

        self.mediaCounter = 0
        self.folderSerach = [f for f in os.listdir() if f.endswith(('.mpg', '.jpg', '.wmv'))]
        self.media.Bind(wx.media.EVT_MEDIA_LOADED, self.mediaPlay, self.media)
        self.media.Bind(wx.media.EVT_MEDIA_FINISHED, self.mediaLoop, self.media)
        self.media.Load(self.folderSerach[self.mediaCounter])

        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.autoRefresh, self.timer)
        self.timer.Start(10000)

        self.Text()
        self.LoadText()
        self.TextSizer()

    def autoRefresh(self, event):
        self.LoadText()

    def mediaPlay(self, event):
        if self.folderSerach[self.mediaCounter].endswith('jpg'):
            self.media.Play()
            #time.sleep(10)
        else:
            self.media.Play()

    def mediaLoop(self, evnet):
        self.media.Stop()
        self.mediaCounter += 1
        print(self.folderSerach)
        if self.mediaCounter > len(self.folderSerach) -1: self.mediaCounter = 0
        self.media.Load(self.folderSerach[self.mediaCounter])

    def Text(self):
        self.title = TransparentText(self.leftPanel, label='test title', style=wx.EXPAND)

        self.staticText1_1 = TransparentText(self.leftPanel, label="test1", style=wx.ALIGN_CENTER)
        self.staticText1_2 = TransparentText(self.leftPanel, label="test2", style=wx.ALIGN_CENTER)
        self.staticText1_3 = TransparentText(self.leftPanel, label="test3", style=wx.ALIGN_CENTER)
        self.staticText1_4 = TransparentText(self.leftPanel, label="test4", style=wx.ALIGN_CENTER)
        self.staticText1_5 = TransparentText(self.leftPanel, label="test5", style=wx.ALIGN_CENTER)
        self.staticText1_6 = TransparentText(self.leftPanel, label="test6", style=wx.ALIGN_CENTER)

        self.staticText2_1 = TransparentText(self.leftPanel, style=wx.ALIGN_CENTER)
        self.staticText2_2 = TransparentText(self.leftPanel, style=wx.ALIGN_CENTER)
        self.staticText2_3 = wx.StaticText(self.leftPanel, style=wx.ALIGN_CENTER)
        self.staticText2_4 = wx.StaticText(self.leftPanel, style=wx.ALIGN_CENTER)
        self.staticText2_5 = wx.StaticText(self.leftPanel, style=wx.ALIGN_CENTER)
        self.staticText2_6 = wx.StaticText(self.leftPanel, style=wx.ALIGN_CENTER)

    def LoadText(self):
        self.cursor.execute("SELECT *FROM CLINIC1")
        for data1 in self.cursor.fetchall(): pass
        self.staticText2_1.SetLabel(data1[1])
        self.staticText2_2.SetLabel(data1[2])
        self.staticText2_3.SetLabel(data1[3])
        self.staticText2_4.SetLabel(data1[4])
        self.staticText2_5.SetLabel(data1[5])
        self.staticText2_6.SetLabel(data1[6])

    def TextSizer(self):
        self.gridSizer = wx.GridSizer(3, 6, 0, 5)
        self.textSizers = (
            self.staticText1_1, self.staticText1_2, self.staticText1_3,
            self.staticText1_4, self.staticText1_5, self.staticText1_6,
            self.staticText2_1, self.staticText2_2, self.staticText2_3,
            self.staticText2_4, self.staticText2_5, self.staticText2_6,
        )
        for textSizer in self.textSizers:
            self.gridSizer.Add(textSizer, 0, wx.ALL|wx.ALIGN_CENTER, 1)
        self.vttextSizer = wx.BoxSizer(wx.VERTICAL)
        self.vttextSizer.Add(self.title, 0, wx.ALL|wx.ALIGN_CENTER|wx.TOP, 1)
        self.vttextSizer.Add(self.gridSizer, 1, wx.ALL|wx.ALIGN_CENTER, 1)
        self.leftPanel.SetSizer(self.vttextSizer)

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

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

if __name__ == '__main__':
    app = wx.App()
    fream = MainFream()
    fream.Show(True)
    app.MainLoop()