如何以编程方式选择/检查wxPython RadioButton?或者换句话说,如何在单选按钮组中定义默认选择?
baud_boxsizer = wx.BoxSizer(wx.HORIZONTAL)
baud_boxsizer.Add(wx.RadioButton(panel, label="9600", style=wx.RB_GROUP))
baud_boxsizer.Add(wx.RadioButton(panel, label="57600"))
...
RadioButton API似乎没有提供这样的功能,单选按钮 group 是一种“虚拟”,因为它只存在于GUI中。
我知道我可以使用RadioBox,但我不知道如何设置样式,因此它不像
答案 0 :(得分:1)
以便有一个编码的答案供将来参考,而不仅仅是评论:
import wx
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "My Frame", size=(600, 300))
self.panel = wx.Panel(self,-1)
#self.panel.Bind(wx.EVT_MOTION, self.OnMove)
my_boxsizer = wx.BoxSizer(wx.HORIZONTAL)
my_apple = wx.RadioButton(self.panel, -1, "Apple")
my_mango = wx.RadioButton(self.panel, -1, "Mango")
my_banana = wx.RadioButton(self.panel, -1, "Banana")
my_orange = wx.CheckBox(self.panel, -1, "Orange", (20,250), (160,-1))
my_boxsizer.Add(my_apple, 0, wx.ALL|wx.EXPAND, 5)
my_boxsizer.Add(my_mango, 0, wx.ALL|wx.EXPAND, 5)
my_boxsizer.Add(my_banana, 0, wx.ALL|wx.EXPAND, 5)
my_boxsizer.Add(my_orange, 0, wx.ALL|wx.EXPAND, 5)
self.panel.SetSizer(my_boxsizer)
my_banana.SetValue(True)
my_orange.SetValue(True)
self.Show()
app = wx.App()
frame = MyFrame()
app.MainLoop()