无法在 Raspberry pi 上为 StaticText 设置 bgcolor(但在 Win10 中没有)

Fails to set bgcolor on StaticText on Raspberry pi (but not in Win10)

我正在尝试在 wxPython 中设置静态文本的背景颜色。我正在使用 .SetBackgroundColour('Red') 方法。当我 运行 我的代码在 windows 10 上时,它按预期工作。但是,当它在 Raspberry pi 上 运行 时,它无法设置背景颜色(和文本对齐方式) ).有人可以帮忙吗?

Picture: Result on windows 10

Picture: Result on Raspberry pi 3b+

我的Github:https://github.com/danneedebro/Problem_bgcolor_static_text

可以在树莓派上找到wxPython4.0.3的代码和wheel文件

这是我的简化代码:

Main.py

import wx


class Example(wx.Frame):
    def __init__(self, parent):
        super(Example, self).__init__(parent, title='Window', size=(300, 100))

        panel = wx.Panel(self)
        LblTextWithBgColor = wx.StaticText(panel, label='This text should have a red background', size=(250, 20), style=wx.ALIGN_CENTER)
        LblTextWithBgColor.SetForegroundColour('Green')
        LblTextWithBgColor.SetBackgroundColour('Red')
        self.Show()


app = wx.App()
Example(None)
app.MainLoop()

您无法在 GTK 中设置 wx.StaticText 的背景颜色。标签只是绘制在父级 window 上,这会阻止您对小部件执行任何操作。这记录在一个不明显的位置:

但是您可以改用 wx.lib.stattext,因为它是一个通用小部件,在所有平台上都应该以相同的方式工作。