本文主要是介绍Tkinter Checkbutton设置了一个多选,为什么初始值都是勾选的:,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
代码如下:
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()
运行如下:
如图所示,选项是被勾选的。如何去掉勾选呢?
这篇关于Tkinter Checkbutton设置了一个多选,为什么初始值都是勾选的:的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!