Python提供了wxpython軟件包,它使我們能夠創建高性能的圖形用戶接口。它是用於Python的cross-platform GUI工具包,Phoenix版本Phoenix是改進的next-generation wxPython,它主要關注速度,可維護性和可擴展性。
在本文中,我們將學習與wxPython的wx.RadioButton類關聯的SetValue()方法。 SetValue()方法將單選按鈕設置為選中或未選中狀態。這不會導致發出wxEVT_RADIOBUTTON事件。如果單選按鈕屬於某個單選按鈕組,則可以僅檢查該組中的一個按鈕,因此隻能在將值設置為True的情況下調用此方法。要取消選中組中的單選按鈕,必須選中同一組中的另一個按鈕。
用法: wx.RadioButton.SetValue(self, value)
參數:
參數 | 輸入類型 | 描述 |
---|---|---|
value | bool | 選中則為True,取消選中為False。 |
例:
Python3
# importing wx library
import wx
APP_EXIT = 1
# create a Example class
class Example(wx.Frame):
# constructor
def __init__(self, *args, **kwargs):
super(Example, self).__init__(*args, **kwargs)
# method calling
self.InitUI()
# method for user interface creation
def InitUI(self):
# parent panel for radio buttons
self.pnl = wx.Panel(self)
# create radio buttons
self.rb1 = wx.RadioButton(self.pnl,
label = 'Button 1',
pos = (30, 10))
self.rb2 = wx.RadioButton(self.pnl,
label = 'Button 2',
pos = (30, 30))
self.rb3 = wx.RadioButton(self.pnl,
label = 'Button 3',
pos = (30, 50))
# set value for the second radio button as true(checked)
self.rb2.SetValue(True)
# main function
def main():
# create an App object
app = wx.App()
# create an Example object
ex = Example(None)
ex.Show()
# running a app
app.MainLoop()
# Driver code
if __name__ == '__main__':
# main function call
main()
輸出:

單選按鈕
相關用法
- wxPython wx.ToolBar AddControl()用法及代碼示例
- wxPython wx.ToolBar AddSeparator()用法及代碼示例
- wxPython wx.RadioButton GetValue()用法及代碼示例
- wxPython wx.RadioBOx IsItemShown()用法及代碼示例
- wxPython wx.RadioBOx SetItemHelpText()用法及代碼示例
- wxPython wx.RadioBox SetItemLabel()用法及代碼示例
- wxPython wx.RadioBox GetItemToolTip()用法及代碼示例
- wxPython wx.RadioBox GetString()用法及代碼示例
- wxPython wx.RadioBox IsItemEnabled()用法及代碼示例
- wxPython wx.RadioBox SetItemToolTip()用法及代碼示例
- wxPython wx.RadioBox SetSelection()用法及代碼示例
- wxPython wx.RadioBox SetString()用法及代碼示例
- wxPython wx.RadioBox ShowItem()用法及代碼示例
注:本文由純淨天空篩選整理自RahulSabharwal大神的英文原創作品 wxPython – SetValue() method in wx.RadioButton。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。