简体   繁体   中英

Wxpython Radio Button Preselected

I have 3 wxpython radio buttons. When run, the first button (Value A) is already selected. How do I make it so no buttons are selected initially?

    self.rb1 = wx.RadioButton(panel, -1, 'Value A', (50, 10), style=wx.RB_GROUP)
    self.rb2 = wx.RadioButton(panel, -1, 'Value B', (10, 30))
    self.rb3 = wx.RadioButton(panel, -1, 'Value C', (10, 50))
    self.Bind(wx.EVT_RADIOBUTTON, self.SetVal, id=self.rb1.GetId())
    self.Bind(wx.EVT_RADIOBUTTON, self.SetVal, id=self.rb2.GetId())
    self.Bind(wx.EVT_RADIOBUTTON, self.SetVal, id=self.rb3.GetId())

Using RB_GROUP it makes buttons mutually exclusive and the first button is always checked. So if you check one this will uncheck the other. If you don't need this mutually exclusive buttons then you can use RB_SINGLE for each of your buttons. See here the docs.

HINT

Maybe a workaround would perhaps be to create a hidden radio-button, which would be selected on creation of the group.

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