How to remove initial wx.RadioBox selection?

て烟熏妆下的殇ゞ 提交于 2019-12-31 02:57:34

问题


I have the following code :

myList =['a','b']
rb=wx.RadioBox(self.panel, -1, "Options :", (0, 0), wx.DefaultSize,myList, 2, wx.RA_SPECIFY_COLS)

When it renders first time I see that a choice has been made how can I change the code that when this radibox rendered first time there are no option has been chosen.


回答1:


The use of a radio box implies, "there is a list of two or more options that are mutually exclusive and the user must select exactly one choice."

The radio box never exists in a state with no choice made. If that's not the case, then don't use a radio box.

If you don't want any of the current radio box options to be selected as default, add another option for "N/A" or "No choice".




回答2:


If your really need to do this then probably the only way is to create your own RadioBox. A RadioBox can easily built from a Panel, StaticBox, StaticBoxSizer and of course RadioButtons.

In the __init__ for your RadioBox use the RadioButtons SetValue() method to set the initial value of the RadioButtons to False.

Take a look at RadioButton demo in the wxpython Demos, there should be enough there to get you started in the right direction.




回答3:


If you just want initial selection invisible, you can have a try with ShowItem(item, show=True)

example here:

myList =['','a','b']
rb=wx.RadioBox(self.panel, -1, "Options :", (0, 0), wx.DefaultSize,myList, 2, wx.RA_SPECIFY_COLS)
rb.ShowItem(0, show=False)



回答4:


Call the the radiobox SetSelection method with a parameter value of -1



来源:https://stackoverflow.com/questions/3691897/how-to-remove-initial-wx-radiobox-selection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!