472,334 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,334 software developers and data experts.

tkinter, radiobuttons, variables

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
print "moo2 var = ",var

Oct 6 '06 #1
1 2542
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 *
  3. master = Tk()
  5. var = IntVar()
  6. var.set(1)  # Set the defalt value to something
  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)
  14. #This should be what you needed.
  15. def print_rb_state():
  16.     print "var = ", var.get()
  18. Button(master, text='Print State!',command=print_rb_state).pack()
  21. master.mainloop()
Oct 10 '06 #2

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

Similar topics

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...
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....
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...
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...
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...
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...
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....
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...
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,...
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...

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.