1.多选按钮创建
from tkinter import *
root=Tk()
Checkbutton(root,text='python').pack()
root.mainloop()
图片.png
2.绑定事件
from tkinter import *
root=Tk()
def callCheckbutton():
print('you check this button')
Checkbutton(root,text='python',command=callCheckbutton).pack()
root.mainloop()
图片.png
3.改变显示的文本
from tkinter import *
root=Tk()
def callCheckbutton():
v.set('check Tkinter')
v=StringVar()
v.set('check python')
Checkbutton(root,text='check python',textvariable=v,command=callCheckbutton).pack()
root.mainloop()
4.绑定变量
from tkinter import *
root=Tk()
v=StringVar()
def callCheckbutton():
print(v.get())
v.set('check python')
Checkbutton(root,text='check python',variable=v,command=callCheckbutton).pack()
root.mainloop()
图片.png
On=1,Off=0
5.设置状态值
from tkinter import *
root=Tk()
def callCheckbutton():
print(v.get())
v=StringVar()
Checkbutton(root,text='check python',variable=v,command=callCheckbutton,onvalue='python',offvalue='tkinter').pack()
root.mainloop()
图片.png
网友评论