Initial selection in a RadioBox

46 views
Skip to first unread message

Mike Conley

unread,
Nov 25, 2009, 1:17:54 PM11/25/09
to wxpytho...@googlegroups.com
Can I get control of the initial selection in a RadioBox?
The following code produces the RadioBox I want, but with the first choice selected. I want to have a box with neither button selected, so that the user makes the first pick.

        btntext = ['In','Out']
        self.btns = wx.RadioBox(control_panel, -1, 'Select By', choices=btntext,
            majorDimension=1, style=wx.RA_SPECIFY_COLS)

I think I can do this by constructing the whole box and individual buttons, but it would be cleaner to use the RadioBox widget if possible.

--
Mike Conley

Cody Precord

unread,
Nov 25, 2009, 1:46:47 PM11/25/09
to wxpytho...@googlegroups.com

Mike Conley

unread,
Nov 25, 2009, 2:07:55 PM11/25/09
to wxpytho...@googlegroups.com
That lets me set a specific button, but I can't set no buttons selected.

--
Mike Conley
 

Robin Dunn

unread,
Nov 25, 2009, 7:17:14 PM11/25/09
to wxpytho...@googlegroups.com

By definition a RadioBox is not supposed to be able to be in a
no-item-selected state.


--
Robin Dunn
Software Craftsman
http://wxPython.org

Mike Conley

unread,
Nov 27, 2009, 12:25:03 PM11/27/09
to wxpytho...@googlegroups.com
On Wed, Nov 25, 2009 at 7:17 PM, Robin Dunn <ro...@alldunn.com> wrote:

By definition a RadioBox is not supposed to be able to be in a
no-item-selected state.



For anyone interested in this there is a way to get the desired visual effect.
Create a RadioBox with one extra dummy button, use SetSelection() to select it and ShowItem(n, False) to hide it.
With a RadioBox the space for the hidden button is reserved and leaves a blank area on the display, but that is not too bad. If you want to get rid of that, build a separate set of radio buttons with one hidden and enclose the set in a static box. Space was not reserved for the hidden button, but you have to do a little more work to catch and handle the events.


--
Mike Conley

Olemis Lang

unread,
Nov 27, 2009, 12:36:40 PM11/27/09
to wxpytho...@googlegroups.com
On Fri, Nov 27, 2009 at 12:25 PM, Mike Conley <mcon...@gmail.com> wrote:
>
>
> On Wed, Nov 25, 2009 at 7:17 PM, Robin Dunn <ro...@alldunn.com> wrote:
>>
>> By definition a RadioBox is not supposed to be able to be in a
>> no-item-selected state.
>>

Well some other frameworks allow this, but it's a matter of style
since the same results may be achieved by including a dummy value
acting as a void option (i.e. if you select this you select nothing
;o) .

>
> For anyone interested in this there is a way to get the desired visual
> effect.
> Create a RadioBox with one extra dummy button, use SetSelection() to select
> it and ShowItem(n, False) to hide it.

Nice hack !

--
Regards,

Olemis.

Blog ES: http://simelo-es.blogspot.com/
Blog EN: http://simelo-en.blogspot.com/

Featured article:
Looking for a technique to create flexible, graphical dashboards ...
- http://feedproxy.google.com/~r/TracGViz-full/~3/KQbN_2EZQGM/0e67afce4357297f

Mike Driscoll

unread,
Nov 30, 2009, 10:21:16 AM11/30/09
to wxPython-users
Most of the time when I see Radio Buttons, I expect one of them to be
selected. Usually adding a button that says "None" or "None of the
above" works just fine.

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

Bryan Oakley

unread,
Nov 30, 2009, 10:26:55 AM11/30/09
to wxpytho...@googlegroups.com
On Fri, Nov 27, 2009 at 11:25 AM, Mike Conley <mcon...@gmail.com> wrote:
>
>
> On Wed, Nov 25, 2009 at 7:17 PM, Robin Dunn <ro...@alldunn.com> wrote:
>>
>> By definition a RadioBox is not supposed to be able to be in a
>> no-item-selected state.
>>
>>
>
> For anyone interested in this there is a way to get the desired visual
> effect.
> Create a RadioBox with one extra dummy button, use SetSelection() to select
> it and ShowItem(n, False) to hide it.

Why hide it, and why make it a dummy? Make an additional button that
says "None" if you simply must support having no selection. Arguably a
much more usable solution is to automatically pick the most likely
choice for the user.

A set of radio buttons says to the user, in effect, "One of these must
be chosen". If you start with one not being chosen you are starting in
an invalid state. That seems like a weird thing to do.

Mike Conley

unread,
Nov 30, 2009, 10:45:24 AM11/30/09
to wxpytho...@googlegroups.com

The two approaches of (1) "always show something" and (2) "none of the above" are what I see most of the time. In this specific case the UI will populate a grid with one of four sets of data that could take a significant amount of time to acquire, and there is no reasonable way to decide what should be displayed first. So, we decided to have the user tell us what to put there by clicking a radio button to pick the first set of data. There is static text on screen reminding them to select something.

An alternative I have seen is a drop down list with the first row saying somenting like "--Select Data--" and four other selections for the data sets.

--
Mike Conley
 

C M

unread,
Nov 30, 2009, 11:14:03 AM11/30/09
to wxpytho...@googlegroups.com
On Mon, Nov 30, 2009 at 10:26 AM, Bryan Oakley <bryan....@gmail.com> wrote:
I'm not sure. If one were taking a questionnaire and one had to choose
between two preferences on each choice, wouldn't having one pre-selected
or a None option seem even odder? Such as this:

What is your sex?

O - Male
O - Female
O - None

In questionnaires, any forced choice between preferences should start with
all choices "blank". That is an invalid state for a user's *choice*,
but is not
an invalid state *to present a user with*. (Imagine going into a restaurant in
which the default meal was pre-selected, or the default meal was None).

Che

Karsten Hilbert

unread,
Nov 30, 2009, 11:18:07 AM11/30/09
to wxpytho...@googlegroups.com
On Mon, Nov 30, 2009 at 10:45:24AM -0500, Mike Conley wrote:

> The two approaches of (1) "always show something" and (2) "none of the
> above" are what I see most of the time. In this specific case the UI will
> populate a grid with one of four sets of data that could take a significant
> amount of time to acquire, and there is no reasonable way to decide what
> should be displayed first. So, we decided to have the user tell us what to
> put there by clicking a radio button to pick the first set of data. There is
> static text on screen reminding them to select something.
>
> An alternative I have seen is a drop down list with the first row saying
> somenting like "--Select Data--" and four other selections for the data
> sets.

You might *ask* (popup etc) the user which set they want when

- focus shifts to this grid
- no data set is pre-selected

Karsten
--
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346

Karsten Hilbert

unread,
Nov 30, 2009, 11:38:53 AM11/30/09
to wxpytho...@googlegroups.com
On Mon, Nov 30, 2009 at 11:14:03AM -0500, C M wrote:

> I'm not sure. If one were taking a questionnaire and one had to choose
> between two preferences on each choice, wouldn't having one pre-selected
> or a None option seem even odder?

It all very much depends on the circumstances. This is
similar to the discussion as to what NULL means in SQL.

> Such as this:
>
> What is your sex?
>
> O - Male
> O - Female
> O - None

The possibility of gender being None is so very remote such
that it doesn't matter. However, *in this case* there's lots
of other NULLs (and missing options in the above list, for
that matter). (I do realize that you are just giving an
example.)

> In questionnaires, any forced choice between preferences should start with
> all choices "blank". That is an invalid state for a user's *choice*,

Why ? After all I can refuse to fill out the questionnaire
in which case I return a blank which, again, in this case,
says something about what I wanted to say (but not exactly
*what* because the only option being to leave it blank is a
very broad way of modelling NULLs).

> but is not
> an invalid state *to present a user with*. (Imagine going into a restaurant in
> which the default meal was pre-selected, or the default meal was None).

Well, there's always the option to leave the restaurant
after having seen the menu. The action of leaving without
ordering (or telling the waiter that no, I won't have
anything) is akin to NULLing my choice.

And, of course, do they pre-select the default meal --
that's what all the big chalked up ads plastering the walls
are about - they want me to select their meal-of-the-day as
that's what's going to give the restaurant the biggest buck
for the bang that day.

This all depends on the exact circumstances and needs to
worked out in the workflow of an application.

C M

unread,
Nov 30, 2009, 1:13:47 PM11/30/09
to wxpytho...@googlegroups.com
I think we're in agreement, in that, yes, circumstance and
needs will dictate what sort of choice structure you provide
your user.

Che

Olemis Lang

unread,
Nov 30, 2009, 2:14:04 PM11/30/09
to wxpytho...@googlegroups.com
On Mon, Nov 30, 2009 at 11:14 AM, C M <cmpy...@gmail.com> wrote:
> On Mon, Nov 30, 2009 at 10:26 AM, Bryan Oakley <bryan....@gmail.com> wrote:
>> On Fri, Nov 27, 2009 at 11:25 AM, Mike Conley <mcon...@gmail.com> wrote:
>>>
>>> On Wed, Nov 25, 2009 at 7:17 PM, Robin Dunn <ro...@alldunn.com> wrote:
>>>>
>>>> By definition a RadioBox is not supposed to be able to be in a
>>>> no-item-selected state.
>>>>
>>>
>>> For anyone interested in this there is a way to get the desired visual
>>> effect.
>>> Create a RadioBox with one extra dummy button, use SetSelection() to select
>>> it and ShowItem(n, False) to hide it.
>>
>> Why hide it, and why make it a dummy? Make an additional button that
>> says "None" if you simply must support having no selection. Arguably a
>> much more usable solution is to automatically pick the most likely
>> choice for the user.
>>
>> A set of radio buttons says to the user, in effect, "One of these must
>> be chosen". If you start with one not being chosen you are starting in
>> an invalid state. That seems like a weird thing to do.
>
> I'm not sure.  If one were taking a questionnaire and one had to choose
> between two preferences on each choice, wouldn't having one pre-selected
> or a None option seem even odder?  Such as this:
>
> What is your sex?
>
> O -  Male
> O -  Female
> O -  None
>

Hey ! Aliens also have the right to take the questionnaire !

XD

--
Regards,

Olemis.

Blog ES: http://simelo-es.blogspot.com/
Blog EN: http://simelo-en.blogspot.com/

Featured article:
[Trac] ANN: TracGViz plugin coming soon ... WAS: Render Ticket ... -
http://feedproxy.google.com/~r/TracGViz-full/~3/0b0ZV8jmvMM/z3dqioodvkzr6hdc

Karsten Hilbert

unread,
Nov 30, 2009, 2:14:39 PM11/30/09
to wxpytho...@googlegroups.com
On Mon, Nov 30, 2009 at 01:13:47PM -0500, C M wrote:

> > Karsten
>
> I think we're in agreement

+1 :-)

Karsten Hilbert

unread,
Nov 30, 2009, 2:22:06 PM11/30/09
to wxpytho...@googlegroups.com
On Mon, Nov 30, 2009 at 02:14:04PM -0500, Olemis Lang wrote:

> > I'm not sure. �If one were taking a questionnaire and one had to choose
> > between two preferences on each choice, wouldn't having one pre-selected
> > or a None option seem even odder? �Such as this:
> >
> > What is your sex?
> >
> > O - �Male
> > O - �Female
> > O - �None
> >
>
> Hey ! Aliens also have the right to take the questionnaire !

I know. That's why my answer to the above included wording
that gender being None is only "very remotely ~" rather than
"im-" possible.

Olemis Lang

unread,
Nov 30, 2009, 2:33:43 PM11/30/09
to wxpytho...@googlegroups.com
On Mon, Nov 30, 2009 at 2:22 PM, Karsten Hilbert
<Karsten...@gmx.net> wrote:
> On Mon, Nov 30, 2009 at 02:14:04PM -0500, Olemis Lang wrote:
>
>> > I'm not sure.  If one were taking a questionnaire and one had to choose
>> > between two preferences on each choice, wouldn't having one pre-selected
>> > or a None option seem even odder?  Such as this:
>> >
>> > What is your sex?
>> >
>> > O -  Male
>> > O -  Female
>> > O -  None
>> >
>>
>> Hey ! Aliens also have the right to take the questionnaire !
>
> I know. That's why my answer to the above included wording
> that gender being None is only "very remotely ~" rather than
> "im-" possible.
>

Ok , just a joke

>:)

Sam23

unread,
Dec 1, 2009, 3:13:09 AM12/1/09
to wxPython-users
I have tried the approach where I built a set of RadioButtons and
enclose it in a StaticBox, hiding the dummy button. It works well in
most situation. But there is a catch with building your own Radio
group this way - if you use keyboard to tab to the radio buttons, have
a preceeding multi-line text control, and there is already a radio
button selected earlier, it won't tab to it; but instead will tab to
the first visible RadioButton - i.e. it will change the value.

I have posted the code and the problem in this forum earlier. You can
look it up.
http://groups.google.com/group/wxpython-users/browse_thread/thread/396f3e91e3694618/307112045a412eac?hl=en#307112045a412eac

I think the idea of having no default button is useful from a data
integrity point of view - the idea being that if there is a pre-
selected value, the user may forget to change it and thus submit an
incorrect value. This is discussed in some groups on how to ensure
accurate data collection. Having no default value is to ensure that
the user makes a selection before the submission is valid - otherwise
the system should reject - stating that a value must be chosen.

It is true that the same result can be achieved by creating a button
that says "None" or "No value selected yet", etc, but it doesn't look
as nice to the end user; and in some cases may be confusing; e.g. if
there are several different choices that requires radio buttons.

Firstly, it is very ugly, there will be an extra button for each
choice, which is of no use except at the beginning, before selection
i.e. you may want to hide it if the same form is being updated at a
later time.

Secondly, the word to use for nothing selected yet can be difficult or
confusing. For example, if we choose "None", and in one of the choices
"None" actually has a meaning, then it is a problem. Ditto if "Not
selected" has a meaning...

For example:
How many of your cars are purple in colour? (a) None (b) None (c) < 2
(d) > 2.
Have you selected a car? (a) Not yet selected (b) Not yet selected
(c) Selected.

So we may end up having to use different words to describe "None" in
different choices - not too good. I thought of using ?, which is least
likely to have confusion, and seems to make the point visually, but it
is not too nice either.

The most elegant way to show 'Not selected' seems to be simply having
none of the radio buttons selected. It is intuitive. HTML allows this,
I think. To be able to do this while having full control of the
appearance may require building a custom control.

Gadge...@live.co.uk

unread,
Dec 1, 2009, 4:57:03 AM12/1/09
to wxpytho...@googlegroups.com

<snip>
>> What is your sex?
>>
>> O - Male
>> O - Female
>> O - None
>>
>
> Hey ! Aliens also have the right to take the questionnaire !
>
> XD
>
>
As an aside why is it that so many companies and organizations ask Name,
Name at birth if different, other names used, (fair enough so far), then ask
Sex Male/Female not Sex Now, Sex at birth if different, etc.? I have worked
with a number of people that would need to respond to the additional
question these days.

Sometimes the preconceived ideas need to be revised because they are wrong
now due to changes in the world other times they need to be changed because
they were never right and sometimes they are still right but it always pays
to question why they are right.

Steve

Reply all
Reply to author
Forward
0 new messages