wxPython - 显示隐藏的单选按钮
在本文中,我们将学习如何显示隐藏的单选按钮。为了取消隐藏/显示单选按钮,我们可以使用 Show()函数。 Show()函数可用于显示和隐藏单选按钮。 Show()函数采用 show 布尔参数,如果为 True,则显示窗口。否则,隐藏它。
Syntax: wx.RadioButton.Show(self, show=True)
Parameters:
Parameter | Input Type | Description |
---|---|---|
show | bool | If True displays the window. Otherwise, hides it. |
Return Type: bool
Returns: True if the window has been shown or hidden or False if nothing was done because it already was in the requested 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))
# create button
self.btn = wx.Button(self.pnl, label ='Btn1',
pos =(30, 50), size =(100, 20))
# hide radio button
self.rb1.Hide()
# bind event function
self.btn.Bind(wx.EVT_BUTTON, self.Onclick)
def Onclick(self, e):
# show hidden radio button
self.rb1.Show()
def main():
app = wx.App()
ex = Example(None)
ex.Show()
app.MainLoop()
if __name__ == '__main__':
main()
输出窗口:
在点击按钮之前
点击按钮后