tk7_checkbutton.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  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. l = tk.Label(window, bg='yellow', width=20, text='empty')
  9. l.pack()
  10. def print_selection():
  11. if (var1.get() == 1) & (var2.get() == 0):
  12. l.config(text='I love only Python ')
  13. elif (var1.get() == 0) & (var2.get() == 1):
  14. l.config(text='I love only C++')
  15. elif (var1.get() == 0) & (var2.get() == 0):
  16. l.config(text='I do not love either')
  17. else:
  18. l.config(text='I love both')
  19. var1 = tk.IntVar()
  20. var2 = tk.IntVar()
  21. c1 = tk.Checkbutton(window, text='Python', variable=var1, onvalue=1, offvalue=0,
  22. command=print_selection)
  23. c2 = tk.Checkbutton(window, text='C++', variable=var2, onvalue=1, offvalue=0,
  24. command=print_selection)
  25. c1.pack()
  26. c2.pack()
  27. window.mainloop()