Python提供了wxpython軟件包,該軟件包允許我們創建高性能的圖形用戶接口。它是用於python的跨平台GUI工具包,Phoenix版本Phoenix是改進的next-generation wxPython,它主要關注速度,可維護性和可擴展性。
在本文中,我們將學習與wxPython的wx.RadioButton類關聯的GetValue()方法。如果選中了單選按鈕,則GetValue()函數用於返回True,否則返回False。 GetValue()函數不需要參數。
用法: wx.RadioButton.GetValue(self)
參數:GetValue()函數不需要參數。
返回:如果選中單選按鈕,則返回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):
# create a parent panel for radio buttons
self.pnl = wx.Panel(self)
# create a radio buttons in frame
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))
# change value of second button to True
self.rb2.SetValue(True)
# print values of radio buttons True
# if checked, False otherwise
print(self.rb1.GetValue())
print(self.rb2.GetValue())
print(self.rb3.GetValue())
# main function
def main():
# create a App object
app = wx.App()
# create a Example object
ex = Example(None)
ex.Show()
# running a app
app.MainLoop()
# Driver code
if __name__ == '__main__':
# main function call
main()
輸出:
False True False

單選按鈕
相關用法
- wxPython wx.ToolBar AddControl()用法及代碼示例
- wxPython wx.ToolBar AddSeparator()用法及代碼示例
- wxPython wx.RadioButton SetValue()用法及代碼示例
- 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 – GetValue() method in wx.RadioButton。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。