开发者

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

开发者_Python百科

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()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜