wxPython 从框架中隐藏单选框小部件
在这篇文章中,我们将学习如何在一个框架中隐藏整个单选框小部件。为了达到这个目的,我们将使用Hide()函数。Hide()函数不需要任何参数。Hide()函数只隐藏无线电盒部件,而不从窗口中移除。同时,无线电盒内的项目的值保持不变。
语法:wx.RadioBox.Hide(self)
参数 Hide() 函数不需要参数。
返回类型: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()
输出窗口。
点击按钮前
点击按钮后