wxPython - 禁用单选按钮
在本文中,我们将了解如何禁用框架中存在的单选按钮。有时,当我们不希望用户按下按钮时,我们可以禁用按钮并且按钮变得不可点击。
为了禁用按钮,我们可以使用与 wxPython 的 wx.RadioButton 类关联的 Disable()函数。
Syntax: wx.RadioButton.Disable(self)
Parameters: No parameters are required by Disable() function
Return Type: bool
Returns: Returns True if the window has been disabled, False if it had been already disabled before the call to this function.
代码示例:
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):
# create parent panel for radio buttons
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
self.rb1.Disable()
def main():
app = wx.App()
ex = Example(None)
ex.Show()
app.MainLoop()
if __name__ == '__main__':
main()
输出窗口: