我正在使用wxpython构建一个gui ..我有按钮和radiobutton,我想
根据gui中的小部件的当前值...插入
来执行此类任务按钮有多个if语句,其中一个if语句是检查是否
选择radiobutton。我不想将事件绑定到单选按钮,所以我有
使用
在插入按钮中检查了它这是定义的辐射按钮
self.rb1 = wx.RadioButton(self.panel, -1, 'Is this a required pre_action to the next
step?', (5, 220))
这是检查条件
if self.rb1.GetValue():
# do something here
还有:
if self.rb1.GetValue() == 'True':
# do some tasks
两种方式(已经相同)当我选择收音机时没有发生任何事情
按钮rb1!那么这个问题究竟是什么呢?
答案 0 :(得分:1)
我不知道那对你不起作用。它对我很有用。请参阅以下示例代码:
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()