wxPython – wx.RadioButton 中的 Enable()函数
在本文中,我们将了解与 wxPython 的 wx.RadioButton 类关联的 Enable()函数。 Enable()函数仅用于启用或禁用用户输入的单选按钮。它需要一个布尔参数 True 来启用和 False 来禁用。
Syntax: wx.RadioButton.Enable(self, enable=True)
Parameters:
Parameter | Input Type | Description |
---|---|---|
enable | bool | If True, enables the window for input. If False, disables the window. |
Return Type: bool
Returns: True if the window has been enabled or disabled, False if nothing was done, i.e. if the window had already been in the specified state.
代码示例:
import wx
APP_EXIT = 1
class Example(wx.Frame):
def __init__(self, *args, **kwargs):
super(Example, self).__init__(*args, **kwargs)
self.InitUI()
def InitUI(self):
self.pnl = wx.Panel(self)
# create radio button at position (30, 10)
self.rb1 = wx.RadioButton(self.pnl, label ='Btn1',
pos =(30, 10), size =(100, 20))
# disable the radio button using Enable() function
self.rb1.Enable(False)
def main():
app = wx.App()
ex = Example(None)
ex.Show()
app.MainLoop()
if __name__ == '__main__':
main()