3

how can I change the foregroundcolor of a disabled TextCtrl from wxPython?
I mean, when I change the color with SetForegroundColour it only changes for enabled status. When I disable the TextCtrl, it remains dark grey even if I set it red, for example.
Thanks in advance!

import wx

class MainFrame(wx.Frame):

    def __init__(self, *args, **kwargs):
        super(MainFrame, self).__init__(*args, **kwargs)
        self.InitUI()
        self.Fit()
        self.Show(True)              

    def InitUI(self):
        text = wx.TextCtrl(self)
        text.SetForegroundColour((255,0,0))
        text.SetValue('Example')
        text.Enable(False)

def main():
    app = wx.App()
    MainFrame(None)
    app.MainLoop()

if __name__ == '__main__':
    main()
4

1 回答 1

1

简短的回答是你不能。
背景和前景色被您禁用的事实所覆盖。您的操作系统环境决定了禁用项目的外观。

当然,这并不意味着您无法解决这个问题。
如果不是禁用/启用该项目,而是设置一个 True/False 标志,则可以在触发事件时检查该标志,并根据标志是 True 还是 False,您是否处理该事件。
这使您可以处理事件并显示您喜欢的任何颜色。

于 2015-08-09T16:41:47.923 回答