简体   繁体   中英

Radio buttons using wxpython

I'm Building a gui using wxpython.. i have buttons and radiobuttons in it, and i wanna

to do such tasks based on what the current values of the widgets in the gui .. the insert

button has a multiple if statement one of these if statement is to check whether a

radiobutton is selected. i dont want to bind an event to the radio button so i have

checked about it in the insert button using

this is the defined radion button

self.rb1 = wx.RadioButton(self.panel, -1, 'Is this a required pre_action to the next   

step?', (5, 220))

and this is the check condition

if self.rb1.GetValue():

    # do something here

and also :

if self.rb1.GetValue() == 'True':

  # do some tasks

in both way (which is already the same) the is nothing happend when i choose the radio

button rb1 ! so what is the problwm of this ?

I don't know what that doesn't work for you. It works for me just fine. See sample code below:

import wx

class MyForm(wx.Frame):

    #----------------------------------------------------------------------
    def __init__(self):
        wx.Frame.__init__(self, None, wx.ID_ANY, "Tutorial")
        panel = wx.Panel(self, wx.ID_ANY)

        self.radio = wx.RadioButton(panel, label="Test", style = wx.RB_GROUP)
        self.radio2 = wx.RadioButton(panel, label="Test2")

        btn = wx.Button(panel, label="Check Radio")
        btn.Bind(wx.EVT_BUTTON, self.onBtn)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.radio, 0, wx.ALL, 5)
        sizer.Add(self.radio2, 0, wx.ALL, 5)
        sizer.Add(btn, 0, wx.ALL, 5)
        panel.SetSizer(sizer)

    #----------------------------------------------------------------------
    def onBtn(self, event):
        """"""
        print "First radioBtn = ", self.radio.GetValue()
        print "Second radioBtn = ", self.radio2.GetValue()

# Run the program
if __name__ == "__main__":
    app = wx.PySimpleApp()
    frame = MyForm().Show()
    app.MainLoop()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM