当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


wxPython wx.RadioButton GetValue()用法及代码示例


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

单选按钮

相关用法


注:本文由纯净天空筛选整理自RahulSabharwal大神的英文原创作品 wxPython – GetValue() method in wx.RadioButton。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。