📌  相关文章
📜  wxPython – wx.RadioButton 中的 GetValue() 方法

📅  最后修改于: 2022-05-13 01:55:04.197000             🧑  作者: Mango

wxPython – wx.RadioButton 中的 GetValue() 方法

Python提供wxpython 允许我们创建功能强大的图形用户界面。它是Python的跨平台GUI工具包,Phoenix版Phoenix是改进的下一代wxPython,主要关注速度、可维护性和可扩展性。

在本文中,我们将学习与 wxPython 的wx.RadioButton类关联的GetValue() 方法GetValue()函数用于在选中单选按钮时返回 True,否则返回 False。
GetValue()函数不需要参数。

例子:

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

单选按钮