代码如下:
from tkinter import *master = Tk()renyuan = ["唐僧", "沙僧", "悟空", "八戒"]def r_change():rec = ""ci = 0for el in vars:rec += el.get() +"、"ci += 1rec = "九点" + rec +"离岗"for i in range(ci):rec = rec.replace("、离岗", "离岗").replace("、、", "、").replace("九点、", "九点")print(rec)vars = []
for ele in renyuan:print(ele)var = StringVar(value="")#print(var.get())vars.append(var)c = Checkbutton(master,text=ele,variable=var,onvalue = "",offvalue = ele +"、",#command=e_change)c.pack()btn = Button(master, text= "提交", command = r_change).pack()mainloop()
运行如下:
如图所示,选项是被勾选的。如何去掉勾选呢?