在wxPython中的RadioButton点击时,启用IntCtrl中的文字输入功能。

问题描述 投票:0回答:1

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

enter image description here

相关代码片段:

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.

我想 "启用 "IntCtrl区域,并将其置于 onClick 方法,但我不知道该怎么做。SetStyle()似乎没有清除wx.TE_READONLY样式的选项,而且我也不希望完全重新创建IntCtrl,因为这样的话,在sizer中重新洗牌会很麻烦。如果有什么方法可以用TextCtrl来实现这个功能,我很乐意换成TextCtrl,然后手动进行字符过滤,但我也没有找到如何启用和禁用这些功能的方法。

radio-button wxpython textctrl
1个回答
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()

enter image description hereenter image description here

© www.soinside.com 2019 - 2024. All rights reserved.