📜  wxPython - 禁用框架中存在的单选框

📅  最后修改于: 2022-05-13 01:55:32.239000             🧑  作者: Mango

wxPython - 禁用框架中存在的单选框

在本文中,我们将学习如何禁用框架中存在的单选框。为了做到这一点,我们将使用 Disable() 方法,该方法使整个 Radio Box 禁用且不可点击。如果窗口已被禁用,Disable() 方法返回 True,如果在调用此函数之前它已被禁用,则返回 False。

Disable()函数不接受任何参数。

代码示例:

import wx
  
  
class FrameUI(wx.Frame):
  
    def __init__(self, parent, title):
        super(FrameUI, self).__init__(parent, title = title, size =(300, 200))
  
        # function for in-frame components
        self.InitUI()
  
    def InitUI(self):
        # parent panel for radio box
        pnl = wx.Panel(self)
  
        # list of choices
        hlist = ['Item One', 'Item Two']
        vlist =['Item One', 'Item Two']
  
        # create radio box with items in horizontal orientation
        self.rbox = wx.RadioBox(pnl, label ='RadioBox', pos =(50, 10), choices = hlist,
                              majorDimension = 0, style = wx.RA_SPECIFY_ROWS)
  
        # create radio box with items in vertical orientation
        self.rbox.Disable()
  
        # set frame in centre
        self.Centre()
        # set size of frame
        self.SetSize((400, 250))
        # show output frame
        self.Show(True)
  
  
  
# wx App instance
ex = wx.App()
# Example instance
FrameUI(None, 'RadioButton and RadioBox')
ex.MainLoop()

输出窗口: