python - 单击按钮时如何更改 wxpython gizmo LED 颜色

标签 python wxpython

我想在单击 wx 按钮时更改 wx gizmos led 的颜色。

我的例子如下。

import wx
import wx.lib.gizmos.ledctrl as led

class Main(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, parent = None, title ="LED test")
        panel = wx.Panel(self)
        self.myLED = led.LEDNumberCtrl(panel, -1, pos = (150,50), size = (100,100))
        self.myLED.SetBackgroundColour("gray")
        self.myButton = wx.Button(panel, -1,  "myButton", pos =(50, 50))
        self.myButton.Bind(wx.EVT_BUTTON, self.changeLEDColor)

    def changeLEDColor(self,event):
        self.myLED.SetBackgroundColour("green")


if __name__ == "__main__":
    app = wx.App()
    frame = Main()
    frame.Show()
    app.MainLoop()

当我点击“mybutton”时,我预计 LED 颜色会变为“绿色”,但它仍然是“灰色”。

我的例子有什么问题吗?

最佳答案

添加 self.Refresh()self.myLED.Refresh() 将触发重绘。这是 docs 的链接。如果它闪烁,请查看 wx.Frame.SetDoubleBuffered(True) - docs

关于python - 单击按钮时如何更改 wxpython gizmo LED 颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57797173/

相关文章:

c++ - 来自 SWIG PyObject_Call 段错误的 Python 回调

python - 在哪里可以找到有关 wxPython 花式文本的更多信息?

python - 懒惰地从 PostgreSQL/Cassandra 创建 Dask DataFrame

python装饰器不从传递的常量中获取值

python - 带有 CheckListBox 弹出窗口的 ComboCtrl - EVT_CHECKLISTBOX 不起作用

Python:wx.Frame子类中的self.control是什么意思?

python - 用于从 werkzeug/Flask 路由规则捕获类型和/或参数化路径的规则

python - 如何删除numpy中具有相同值的列

python - 在 python 中插入或更新一条 peewee 记录

python - 允许Python脚本打开目录中的任何文件而不是硬编码名称的解决方案