tk5_radiobutton.py 928 B

123456789101112131415161718192021222324252627282930313233
  1. # View more python learning tutorial on my Youtube and Youku channel!!!
  2. # Youtube video tutorial: https://www.youtube.com/channel/UCdyjiB5H8Pu7aDTNVXTTpcg
  3. # Youku video tutorial: http://i.youku.com/pythontutorial
  4. import tkinter as tk
  5. window = tk.Tk()
  6. window.title('my window')
  7. window.geometry('200x200')
  8. var = tk.StringVar()
  9. l = tk.Label(window, bg='yellow', width=20, text='empty')
  10. l.pack()
  11. def print_selection():
  12. l.config(text='you have selected ' + var.get())
  13. r1 = tk.Radiobutton(window, text='Option A',
  14. variable=var, value='A',
  15. command=print_selection)
  16. r1.pack()
  17. r2 = tk.Radiobutton(window, text='Option B',
  18. variable=var, value='B',
  19. command=print_selection)
  20. r2.pack()
  21. r3 = tk.Radiobutton(window, text='Option C',
  22. variable=var, value='C',
  23. command=print_selection)
  24. r3.pack()
  25. window.mainloop()