Enable/disable 在 wxPython 中单击 RadioButton 上的 IntCtrl 中的文本输入

Enable/disable text entry in IntCtrl on RadioButton click in wxPython

我有一个简单的图形用户界面,它有两个单选按钮和一个用于文本输入的 IntCtrl。最初,我选择了顶部单选按钮并禁用了 IntCtrl(不幸的是,我不知道如何将其设置为空白或 "grayed out"):

相关代码片段:

def loadSettingsPanel(self):
    panel = wx.Panel(self)

    self.exposureAutomatic = wx.RadioButton(panel, label="Automatic (1ms)", style=wx.RB_GROUP)
    self.exposureManual = wx.RadioButton(panel, label="Manual")
    self.exposureValue = wx.lib.intctrl.IntCtrl(panel, style=wx.TE_READONLY)

    self.exposureManual.Bind(wx.EVT_RADIOBUTTON, self.onClick)

    # Add sizers, etc.

我想在 onClick 方法中 "enable" IntCtrl 区域,但我不知道该怎么做。 SetStyle() 似乎没有清除 wx.TE_READONLY 样式的选项,我不希望完全重新创建 IntCtrl,因为那样重新调整 sizer 中的所有内容会很烦人。如果有某种方法可以使用 TextCtrl 执行此操作,我很乐意切换到该方法并手动进行字符过滤,但我也无法弄清楚如何 enable/disable 这些。

使用 Enable 函数而不是样式。

import wx
import wx.lib.intctrl

class MyFrame(wx.Frame):

    def __init__(self, parent):

        wx.Frame.__init__(self, parent, -1, "Intctrl Demo")

        panel = wx.Panel(self)
        self.exposureAutomatic = wx.RadioButton(panel, label="Automatic (1ms)", style=wx.RB_GROUP, pos=(50,50))
        self.exposureManual = wx.RadioButton(panel, label="Manual", pos=(50,80))
        self.ic = wx.lib.intctrl.IntCtrl(panel, -1, pos=(150, 80))
        self.ic.Enable(False)
        self.Bind(wx.EVT_RADIOBUTTON, self.onClick)

    def onClick(self, event):
        self.ic.Enable(self.exposureManual.GetValue())


app = wx.App()

frame = MyFrame(None)
app.SetTopWindow(frame)
frame.Show()

app.MainLoop()