wxPython - 从框架中隐藏单选框
在本文中,我们将学习如何将整个 Radio Box 小部件隐藏在框架内。为此,我们将使用 Hide()函数。 Hide()函数不需要参数。 Hide()函数仅隐藏 Radio Box 小部件,而不会从窗口中删除。此外,Radio Box 内的项目值保持不变。
Syntax: wx.RadioBox.Hide(self)
Parameters Hide() function requires no parameters.
Return Type: bool
代码示例:
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
lblList = ['Radio One', 'Radio Two']
# create radio box containing above list
self.rbox = wx.RadioBox(pnl, label ='RadioBox', pos =(80, 10), choices = lblList,
majorDimension = 1, style = wx.RA_SPECIFY_ROWS)
# create a button in the frame
self.btn = wx.Button(pnl, 1, "Hide RadioBox", pos =(100, 100));
# bind a function with button
self.btn.Bind(wx.EVT_BUTTON, self.onclick)
# set frame in centre
self.Centre()
# set size of frame
self.SetSize((400, 250))
# show output frame
self.Show(True)
def onclick(self, e):
# hide radio box from the frame
self.rbox.Hide()
# wx App instance
ex = wx.App()
# Example instance
FrameUI(None, 'RadioButton and RadioBox')
ex.MainLoop()
输出窗口:
在点击按钮之前
点击按钮后