创建一个复选框
### 多选框checkbutton
### command执行事件
ckB_1 = tk.Checkbutton(root, text='python', command=clickCkb).pack()
绑定普通事件
### 绑定事件函数
def clickCkb():
print('点击了事件')
绑定选中和未选中的事件
v = tk.StringVar()
def callCkb():
print(v.get())
###多选框指定选中onvalue
###多选框指定未选中offvalue
ckB_5 = tk.Checkbutton(root, variable=v, text='tkinter', onvalue='dakai', offvalue='guanbi', command=callCkb).pack()
文本代码如下:
import tkinter as tk
root = tk.Tk()
### 绑定事件函数
def clickCkb():
print('点击了事件')
v = tk.StringVar()
def callCkb():
print(v.get())
### 多选框checkbutton
### command执行事件
ckB_1 = tk.Checkbutton(root, text='python', command=clickCkb).pack()
ckB_2 = tk.Checkbutton(root, text='c++', command=clickCkb).pack()
ckB_3 = tk.Checkbutton(root, text='java', command=clickCkb).pack()
ckB_4 = tk.Checkbutton(root, text='php', command=clickCkb).pack()
###多选框指定选中onvalue
###多选框指定未选中offvalue
ckB_5 = tk.Checkbutton(root, variable=v, text='tkinter', onvalue='dakai', offvalue='guanbi', command=callCkb).pack()
root.mainloop()