tKinter如何在取消选中复选框时禁用Entry,并在选中复选框时启用它

问题描述 投票:-1回答:1

来自tkinter import * window = Tk()

nor = {} ent = {}

对于范围内的i(10):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()

tkinter python-3.7
1个回答
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()
© www.soinside.com 2019 - 2024. All rights reserved.