【问题标题】:Enable/disable text entry in IntCtrl on RadioButton click in wxPython在 wxPython 中单击 RadioButton 上的 IntCtrl 启用/禁用文本输入
【发布时间】:2020-09-21 05:20:43
【问题描述】:

我有一个简单的 gui,它有两个单选按钮和一个用于文本输入的 IntCtrl。最初,我选择了顶部单选按钮并禁用了 IntCtrl(不幸的是,我不知道如何将其设置为空白或“变灰”):

相关代码sn-p:

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

【问题讨论】:

    标签: radio-button wxpython textctrl


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-02
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      • 2017-09-14
      • 2020-12-06
      • 1970-01-01
      相关资源
      最近更新 更多