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!
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 : - from Tkinter import * 1
-
-
root = Tk()
-
-
v1=IntVar()
-
v2=IntVar()
-
-
button1=Radiobutton(root, text="1", value=1, variable=v1)
-
button2=Radiobutton(root, text="2", value=2, variable=v1)
-
button3=Radiobutton(root, text="3", value=3, variable=v2)
-
button4=Radiobutton(root, text="4", value=4, variable=v2)
-
-
button1.grid(row=1, column=0)
-
button2.grid(row=2, column=0)
-
button3.grid(row=1, column=1)
-
button4.grid(row=2, column=1)
-
-
def dialog():
-
if v1.get()*v2.get()==3:
-
print 'a'
-
if v1.get()*v2.get()==4:
-
print 'b'
-
if v1.get()*v2.get()==6:
-
print 'c'
-
if v1.get()*v2.get()==8:
-
print 'd'
-
-
button=Button(root, text='Click', command=dialog)
-
button.grid(row=3, column=0, pady=5, padx=10)
-
-
close=Button(root, text='Exit', command=root.quit)
-
close.grid(row=4, column=0, pady=10)
-
-
root.title('Multi radio button!')
-
root.mainloop()
-
A "dispatch dictionary" may come in handy here: -
>>> def funct1():
-
... print 'a'
-
...
-
>>> def funct2():
-
... print 'b'
-
...
-
>>> def funct2():
-
... print 'b'
-
...
-
>>> def funct3():
-
... print 'c'
-
...
-
>>> def funct4():
-
... print 'd'
-
...
-
>>> dispatchDict = {2:funct1, 3:funct2, 6:funct3, 8:funct4}
-
>>> actionCode = 3
-
>>> dispatchDict[actionCode]()
-
b
-
>>>
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
| |