tKinter如何在未选中复选框的情况下禁用条目,并在选中按钮的情况下启用条目

时间:2019-03-05 18:46:42

标签: tkinter python-3.7

从tkinter导入* window = Tk()

nac = {} ent = {}

对于范围(10)中的i:     de = IntVar()     nac [i] = IntVar()

na=Checkbutton(window, text='%s' % (i), borderwidth=1,variable = 
nac[i], onvalue = 1, offvalue = 0,command=lambda e=ent, 
v=nac[i]:naccheck(e,v))
na.grid(row=i, column=0)
ent[i]=Entry(window,textvariable=de, state = DISABLED)
ent[i].grid(column=1,row=i,padx=20)

window.mainloop()

1 个答案:

答案 0 :(得分:0)

尝试一下:

from tkinter import *

def entry():
    ent[i].configure(state = NORMAL)

window=Tk()

nac = {}
ent = {}

for i in range(10):
    de = IntVar()
    nac[i]=IntVar()

na=Checkbutton(window, text='%s' % (i), borderwidth=1,variable = nac[i],
               onvalue = 1, offvalue = 0,command=entry)
na.grid(row=i, column=0)
ent[i]=Entry(window,textvariable=de, state = DISABLED)
ent[i].grid(column=1,row=i,padx=20)
window.mainloop()