tkinter实现单选框和复选框

一 代码

  1. import tkinter
  2. root = tkinter.Tk()
  3. r = tkinter.StringVar()
  4. r.set('1')
  5. radio = tkinter.Radiobutton(root,
  6. variable = r,
  7. value ='1',
  8. text='Radio1')
  9. radio.pack()
  10. radio = tkinter.Radiobutton(root,
  11. variable = r,
  12. value ='2',
  13. text='Radio2')
  14. radio.pack()
  15. radio = tkinter.Radiobutton(root,
  16. variable = r,
  17. value ='3',
  18. text='Radio3')
  19. radio.pack()
  20. radio = tkinter.Radiobutton(root,
  21. variable = r,
  22. value ='4',
  23. text='Radio4')
  24. radio.pack()
  25. c = tkinter.IntVar()
  26. c.set(1)
  27. check = tkinter.Checkbutton(root,
  28. text='Checkbutton',
  29. variable = c,
  30. onvalue =1,
  31. offvalue=2
  32. )
  33. check.pack()
  34. root.mainloop()
  35. print(r.get())
  36. print(c.get())
二 运行结果

 

猜你喜欢

转载自cakin24.iteye.com/blog/2384531