无法在 Raspberry pi 上的 StaticText 上设置 bgcolor(但不在 Win10 中) [英] Fails to set bgcolor on StaticText on Raspberry pi (but not in Win10)

查看:72
本文介绍了无法在 Raspberry pi 上的 StaticText 上设置 bgcolor(但不在 Win10 中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to set the backgroundcolor of a StaticText in wxPython. I am using the method .SetBackgroundColour('Red'). That works as expected when I run my code on windows 10. However, when it runs on a Raspberry pi it fails to set the background colour (and the text alignment). Can someone help?

图片:Windows 10 上的结果

图片:在 Raspberry pi 3b+ 上的结果

在我的 Github 上可以找到在 raspberry 上为 wxPython4.0.3 构建的代码和轮子文件: https://github.com/danneedebro/Problem_bgcolor_static_text

这是我的简化代码:

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 的背景颜色.标签只是绘制在父窗口上,这会阻止您对小部件执行任何操作.这记录在一个不明显的位置:

You cannot set the background color of wx.StaticText in GTK. The label is just drawn on the parent window, which prevents you from doing much of anything with the widget. This is documented in a non-obvious location:

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

However you can use the wx.lib.stattext instead as it is a generic widget that should work the same way on all platforms.

这篇关于无法在 Raspberry pi 上的 StaticText 上设置 bgcolor(但不在 Win10 中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆