crystalattice írta:
In my GUI app, I have a radio box allowing the user to pick his/her
gender. When I click a button, I'd like the radio box to tell the
program which choice is marked. I can get it to work when I manually
pick a choice but I get an error when the choice is left at the default
value, which is "Male".
I have the radio box tied to an event to "see" when a choice is made,
but how does it work if the person just leaves the default value? I've
looked at the wxPython demo but the radio box actions only work for
changing values.
I'm not sure if I understood your problem. You can call the
wxRadioBox.GetSelection method anytime to get the current value.
If you need that value very often (e.g. thousand times per sec) then you
can "shadow" the default value in an instance variable.
Example (untested):
class MyClass(wx.Frame):
"""In this frame, you can use the curchoice variable after
construction."""
def __init__(self):
# ... create your frame here...
r =self.radio = wx.RadioBox(self,-1,choiches=['One','Two','Three'])
# Set default value
r.SetSelection(0) # This does not cause a
wxEVT_COMMAND_RADIOBOX_SELECTED event to get emitted.
self.curchoice = 0
# Bind the event
r.Bind(
wx.EVT_COMMAND_RADIOBOX_SELECTED,
self.OnRadioChanged,
r
)
def OnRadioChanged(self,event):
self.curchoice = self.radio.GetSelection()
# Do whatever you want here...
event.Skip()