469,921 Members | 2,215 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,921 developers. It's quick & easy.

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 2434
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

Post your reply

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

Similar topics

2 posts views Thread by Marcus Schneider | last post: by
5 posts views Thread by max(01)* | last post: by
11 posts views Thread by William Gill | last post: by
3 posts views Thread by William Gill | last post: by
4 posts views Thread by Kevin Walzer | last post: by
2 posts views Thread by Gigs_ | last post: by
3 posts views Thread by Dream | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.