我想在单击 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/