首页 > 解决方案 > 单击按钮时如何更改wxpython gizmo LED颜色

问题描述

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

我的例子如下。

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

当我单击“我的按钮”时,我预计 LED 的颜色会变为“绿色”,但它仍然是“灰色”。

我的例子有什么问题?

标签: pythonwxpython

解决方案


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


推荐阅读