473,387 Members | 1,441 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.

tkinter, radiobuttons, variables

3
This is my code. I've tried a trillion different things. But basically what I want is the radiobuttons to appear. Select one and hit the okay button. Then the screen prints out the var of which button was selected (just to verify). And I want the whole program to wait and do nothing until this process is done. (What I'd want to do next is another radiobutton set, but I'm not there yet.)

Help! I've been researching this online all day today. I've found tons of posts with people with the same problems, but either the solutions weren't available, or made no sense to me.

Thank you very much in advance.





from Tkinter import *

master = Tk()

var = IntVar()

Radiobutton(master, text="One", variable=var, value=1).pack(anchor=W)
Radiobutton(master, text="Two", variable=var, value=2).pack(anchor=W)

Button(master, text='OK!',command=master.destroy).pack()

print "moo1 var = ",var
master.wait_variable
print "moo2 var = ",var

master.mainloop()
Oct 6 '06 #1
1 2593
bartonc
6,596 Expert 4TB
I future, read posting or reply guidelines to learn how to use CODE tags so you post looks like this:

Expand|Select|Wrap|Line Numbers
  1. from Tkinter import *
  2.  
  3. master = Tk()
  4.  
  5. var = IntVar()
  6. var.set(1)  # Set the defalt value to something
  7.  
  8. # I like to keep the instanciated button around in case I want to config it later
  9. rb1 = Radiobutton(master, text="One", variable=var, value=1)
  10. rb2 = Radiobutton(master, text="Two", variable=var, value=2)
  11. rb1.pack(anchor=W)
  12. rb2.pack(anchor=W)
  13.  
  14. #This should be what you needed.
  15. def print_rb_state():
  16.     print "var = ", var.get()
  17.  
  18. Button(master, text='Print State!',command=print_rb_state).pack()
  19.  
  20.  
  21. master.mainloop()
  22.  
Oct 10 '06 #2

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

Similar topics

1
by: Josh | last post by:
Caution, newbie approaching... I'm trying to come up with a very simple Tkinter test application that consists of a window with a drop-down menu bar at the top and a grid of colored rectangles...
2
by: Marcus Schneider | last post by:
Sorry if this is an extremely stupid question: I produced some Python modules with TKinter stuff and now I want to use that from my main program. The windows have wuite some user interaction....
5
by: max(01)* | last post by:
hello. the following code: 1 from Tkinter import * 2 3 class MiaApp: 4 def __init__(self, genitore): 5 self.mioGenitore = genitore 6 self.i = IntVar()
11
by: William Gill | last post by:
I am placing radiobuttons in a 4 X 4 matrix (using loops) and keep references to them in a 2 dimensional list ( rBtns ). It works fine, and I can even make it so only one button per column can be...
3
by: William Gill | last post by:
Working with tkinter, I have a createWidgets() method in a class. Within createWidgets() I create several StringVars() and assign them to the textvariable option of several widgets. Effectively my...
4
by: Kevin Walzer | last post by:
I'm trying to manage user preferences in a Tkinter application by initializing some values that can then be configured from a GUI. The values are set up as a dict, like so: self.prefs= {...
2
by: Gigs_ | last post by:
I'm working on tkinter paint program, mostly to learn tkinter canvas. I have method which create buttons for oval, rectangle, line, polygon etc. How to make oval button to be sunken when i click it...
3
by: seanacais | last post by:
I'm trying to build an unknown number of repeating gui elements dynamically so I need to store the variables in a list of dictionaries. I understand that Scale "variable" name needs to be a...
3
by: Dream | last post by:
The code create 2 windows. 2 radiobuttons are put on the second window. A control variable "v" is binded to the 2 widgets. But when I run the code, I found the control variable not binded...
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.