【发布时间】:2012-07-14 11:36:40
【问题描述】:
我想用 TkInter 在 Python 中创建一个复选框列表,并尝试使用一个按钮选择所有复选框。
from tkinter import *
def create_cbuts():
for i in cbuts_text:
cbuts.append(Checkbutton(root, text = i).pack())
def select_all():
for j in cbuts:
j.select()
root = Tk()
cbuts_text = ['a','b','c','d']
cbuts = []
create_cbuts()
Button(root, text = 'all', command = select_all()).pack()
mainloop()
我怕他不填名单cbuts:
cbuts.append(Checkbutton(root, text = i).pack())
【问题讨论】:
-
Checkbutton(root, text=i).pack()不会返回您认为的结果。 -
是的,它不会返回列表的对象。
标签: python list checkbox tkinter