473,387 Members | 1,700 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,387 software developers and data experts.

Radio Buttons

208 100+
I have two radiobuttons: onRadio and offRadio....When the program loads I want the onRadio button to be selected. How do I do this?

I've tried:
onRadio.select() but this does nothing.
Mar 9 '07 #1
6 6009
bartonc
6,596 Expert 4TB
I have two radiobuttons: onRadio and offRadio....When the program loads I want the onRadio button to be selected. How do I do this?

I've tried:
onRadio.select() but this does nothing.
Depends on which GUI Toolkit you're using. I see that you are a .NETer; new to python?
Mar 9 '07 #2
Silent1Mezzo
208 100+
Depends on which GUI Toolkit you're using. I see that you are a .NETer; new to python?
New to python. Experienced at .NET

I'm using the TK GUI toolkit
Mar 9 '07 #3
bartonc
6,596 Expert 4TB
New to python. Experienced at .NET

I'm using the TK GUI toolkit
That would be "Tkinter" in python.
To group radio buttons in Tkinter you must associate something I like to call a Tk PyVar. This variable (common to all buttons in a group) is automaticly updated when the buttons are push and setting it programmatically sets the buttons. It can be an integer or a string.
For info, see this link:
radio button patterns
Mar 9 '07 #4
bartonc
6,596 Expert 4TB
New to python. Experienced at .NET

I'm using the TK GUI toolkit
I'm curious; are you just checking python out; trying to find something easier than .NET; have you heard of MS's IronPython (sort of a marriage between python and .NET, from what I understand)?
Mar 9 '07 #5
Silent1Mezzo
208 100+
That would be "Tkinter" in python.
To group radio buttons in Tkinter you must associate something I like to call a Tk PyVar. This variable (common to all buttons in a group) is automaticly updated when the buttons are push and setting it programmatically sets the buttons. It can be an integer or a string.
For info, see this link:
radio button patterns

I have the radio buttons working my problem is that I need one of them preselected when the program loads....and the .select() isn't working

Expand|Select|Wrap|Line Numbers
  1. onRadio = Radiobutton(onOff, text = "On", value = 0, variable = v)
  2. onRadio.pack(side = BOTTOM, anchor = S)
  3. onRadio.select()
This should select the onRadio but it doesnt.
Mar 9 '07 #6
bartonc
6,596 Expert 4TB
I have the radio buttons working my problem is that I need one of them preselected when the program loads....and the .select() isn't working

Expand|Select|Wrap|Line Numbers
  1. onRadio = Radiobutton(onOff, text = "On", value = 0, variable = v)
  2. onRadio.pack(side = BOTTOM, anchor = S)
  3. onRadio.select()
This should select the onRadio but it doesnt.
Expand|Select|Wrap|Line Numbers
  1. v = StringVar()
  2. v.set("On")  # or whatever you want the default to be
  3. onRadio = Radiobutton(onOff, text = "On", value = 0, variable = v)
  4. onRadio.pack(side = BOTTOM, anchor = S)
  5.  
select() may work on buttons with no variable associated with them, I don't remember. Once you have the variable, use it to control the group. It makes sense since the other buttons need to be informed of the change and act accordingly (and this is ALL that they have in common).

I should point out that Tk is only very basic and useful for cross-platform development (to a point) because it "comes with" most python installations. There are other cross platform Gui ToolKits which do deliver a native look on Windows and *nix and Mac and have much more intuitive contructors and vast library of widgets. The first think most people notice when developing with Tkinter is that there is no ComboBox widget. Some tree widget support and D&D support has be kluged onto it, but if you look at the source code for IDLE, you'll find that the Text widget in Tk never did work very well. It is a good place for beginners to start, but anyone familiar with an overloaded environment like .NET will find it lacking in a hurry.
Mar 9 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: sman | last post by:
Hi, I recently read this article on About.com on how to create required fields for a form: http://javascript.about.com/library/scripts/blformvalidate.htm Everything works great except that there...
2
by: Jeff | last post by:
I'm trying to create a dynamic form that can have multiple groups of radio buttons (each group has two buttons) with the same name. Essentially, the form allows a user to enter as many names as...
4
by: Oscar Monteiro | last post by:
I Have to sets of Radio buttons like so: <input type="radio" name=p1 value=1> <input type="radio" name=p1 value=2> <input type="radio" name=p1 value=3> <br> <input type="radio" name=p2 value=1>...
6
by: Craig Keightley | last post by:
I have a page that has n number of radio groups (yes/No) how can i prevent the form being submitted if more than one radio group is not selected? By default all radio groups are unchecked ...
2
by: Rob | last post by:
Hi all, I've got multiple sets of radio button that are dynamically created in code and populated by a database query. The query returns about 20 recordsets with 3 radio buttons per recordset and...
2
by: James P. | last post by:
Help, I need to display radio buttons on a form. The data is from SQL table: each row in each table is displayed as a radio button. I have multiple SQL tables so I understand I need to put...
1
by: kenny8787 | last post by:
Hi, can anyone help here? I have the following code generated from a database, I want to have javascript calculate the costs of the selected items using radio buttons, subtotal the costs and...
2
by: dpazza | last post by:
Hi, I'm creating a quiz on using a form in VB 2005 express. I have four sets of questions and answers (labels and radio buttons) and I change between which set of questions is currently shown on...
4
by: Blasting Cap | last post by:
I have a page that has a number of radio buttons that will be displayed to different access levels of a user who logs in to my website. For instance, if there are a dozen buttons, user1 will see...
11
by: Twayne | last post by:
Hi, Newbie to PHP here, no C or other relevant background, so pretty niave w/r to the nuances etc. but I think this is pretty basic. XP Pro, SP2+, PHP 4.4.7, XAMPP Local Apache Server...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.