var_list = []
# 将列表项转换为复选框
for index, item in enumerate(ls):
var = tkinter.BooleanVar()
var_list.append(var)
check_button = tkinter.Checkbutton(root, text=item, variable=var)
check_button.place(x=160, y=35 + 20 * index)
# 反选功能函数
def invert():
for var in var_list:
var.set(not var.get())
# 全选功能函数
def all():
for var in var_list:
var.set(True)
# 重置功能函数
def cancel():
for var in var_list:
var.set(False)
# 确定功能函数
def run():
selected_items = []
for i, var in enumerate(var_list):
if var.get():
selected_items.append(ls[i])
result = "您选择了" + "".join(selected_items)
lb2.config(text=result, fg="red")