472,783 Members | 1,078 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,783 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 4167
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: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.