473,385 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

wxPython default radiobox choice

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.

Aug 24 '06 #1
2 4214
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()

Aug 24 '06 #2

Laszlo Nagy wrote:
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()
Thanks for the response. I got it working now. I was trying to bind
the radio box to an event, rather than just calling GetSelection(). I
thought I needed to bind it to make it work (based on the wxPython demo
code).

Aug 24 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Austin | last post by:
Every time i use wxRadioBox, it will show the box. I just want the options show on the panel. What could i do?
25
by: TPJ | last post by:
GUI's etc: PyGtk on Windows "(...) So if someone develops mainly for X and just wants to make sure that it is not impossible to run on Windows, you can use PyGTK. (...)", July 2nd, 1999 pyGTK...
0
by: Robin Dunn | last post by:
Announcing ---------- The 2.6.3.2 release of wxPython is now available for download at http://wxpython.org/download.php. This is a mostly bug fix release and takes care of several "unfortunate...
16
by: Andrea Gavana | last post by:
Hi Diez & All, Do you mind explaining "why" you find it *buttugly*? I am asking just out of curiosity, obviously. I am so biased towards wxPython that I won't make any comment on this thread...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.