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

radio button problems :(

Hi all,
I'm using Python 2.5.1 and TkInter.
Hey here is the problem. Suppose I have 4 radio buttons (lets say values 1,2,3 and 4). They arranged in 2 columns (Each of the 2 columns has 2 radio buttons). I want to produce a specific action whenever I select a total of 2 radio buttons (and click on the "Submit" button), 1 from each column. Suppose say 1 and 3 are selected it should print 'a'. If 1 and 4, then print 'b' and similarly for radio button number 2. Any ideas? I think that 2 variables v1 and v2 for the 2 sets of radio buttons should be defined and the 'dct' command implemented though I'm stuck at this. However any other ideas will be great too.... Looking forward .... Thanks!
Dec 4 '07 #1
2 1701
Hello all again...
Hey I managed to find a solution to the problem :)... but would welcome alternative suggestions. For public scrutiny the code is :

Expand|Select|Wrap|Line Numbers
  1. from Tkinter import *                                                       1
  2.  
  3. root = Tk()
  4.  
  5. v1=IntVar()
  6. v2=IntVar()
  7.  
  8. button1=Radiobutton(root, text="1", value=1, variable=v1)
  9. button2=Radiobutton(root, text="2", value=2, variable=v1)
  10. button3=Radiobutton(root, text="3", value=3, variable=v2)
  11. button4=Radiobutton(root, text="4", value=4, variable=v2)
  12.  
  13. button1.grid(row=1, column=0)
  14. button2.grid(row=2, column=0)
  15. button3.grid(row=1, column=1)
  16. button4.grid(row=2, column=1)
  17.  
  18. def dialog():
  19.     if v1.get()*v2.get()==3:
  20.         print 'a'
  21.     if v1.get()*v2.get()==4:
  22.         print 'b'
  23.     if v1.get()*v2.get()==6:
  24.         print 'c'
  25.     if v1.get()*v2.get()==8:
  26.         print 'd'
  27.  
  28. button=Button(root, text='Click', command=dialog)
  29. button.grid(row=3, column=0, pady=5, padx=10)
  30.  
  31. close=Button(root, text='Exit', command=root.quit)
  32. close.grid(row=4, column=0, pady=10)
  33.  
  34. root.title('Multi radio button!')
  35. root.mainloop()
  36.  
Dec 4 '07 #2
bartonc
6,596 Expert 4TB
A "dispatch dictionary" may come in handy here:
Expand|Select|Wrap|Line Numbers
  1. >>> def funct1():
  2. ...     print 'a'
  3. ...     
  4. >>> def funct2():
  5. ...     print 'b'
  6. ...     
  7. >>> def funct2():
  8. ...     print 'b'
  9. ...     
  10. >>> def funct3():
  11. ...     print 'c'
  12. ...     
  13. >>> def funct4():
  14. ...     print 'd'
  15. ...     
  16. >>> dispatchDict = {2:funct1, 3:funct2, 6:funct3, 8:funct4}
  17. >>> actionCode = 3
  18. >>> dispatchDict[actionCode]()
  19. b
  20. >>> 
Dec 4 '07 #3

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

Similar topics

1
by: David | last post by:
Hi, May I know how to create data dynamically in a combo box after clicking on a radio button ? Data are retrieved using a store procedure from a SQL Server. For example : Click Radio Button...
2
by: jimi_xyz | last post by:
Sorry if this isn't the correct group, i don't think there is a group for straight HTML. I am trying to create a type of search engine. There are two radio buttons at the top, in the middle there...
2
by: Pauly | last post by:
I have a group of three radio buttons on a group box. In my database I have three columns all of data type bit. I want to bind each button so that if it is 1 then it selects the appropriate...
2
by: NishSF | last post by:
Would anyone have any suggestions/javascript code so that if one clicks the Radio Button "Yes" below he has the option of selecting any of the six CheckBox below. If the user clicks on Radio Button...
10
by: Scuba Rob | last post by:
I am having problems on getting the radio button to work with my.settings correctly. I want the program to check to see which one was last saved to use at startup. The closest I have come is that I...
7
by: nathaniel.k.lee | last post by:
Is it not possible, in IE, to dynamically click a radio button? I'm grabbing some values from a database and using them to populate radio buttons on a page. I have alternate code for Firefox...
1
by: Shane | last post by:
I think that I found a bug in the Radio Button, and I wanted to give everybody a "Heads Up". I spent three days doing trial and error until I found a work around. I created a user control with a...
10
by: IchBin | last post by:
I am trying to set the state of a radio button. I do not see what I am doing wrong. Sorry, I am new at this.. I need another set of eyes to look at this snip of code. I am trying to set the radio...
7
by: IchBin | last post by:
I am trying to programmatically set a radio button in a table of radio buttons. I have two problems with the code below: 1 - I can not prepare the <Formstatement to be printed by php. (syntax...
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
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...

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.