from tkinter import *
from tkinter import font
class AA:
def __init__(self):
window=Tk()
self.var=IntVar()
checkbutton=Checkbutton(window,text="add",variable=self.var,state="normal")
checkbutton.pack()
#回调command
checkbutton.config(command=self.callback)
# checkbutton.invoke() #运行回调函数
# checkbutton.select() #设定初试状态为checked
# checkbutton.deselect() #设定初试状态为unchecked
window.mainloop()
def callback(self):
print("the option is "+("checked" if self.var.get()==1 else "unchecked"))
AA()
# 参考文献:
# http://effbot.org/tkinterbook/checkbutton.htm
python-tkinter-Checkbutton
最新推荐文章于 2024-08-15 11:16:21 发布