需要注意:
①当控件的state='disabled'时,属性设置可能有所变化,比如背景颜色的设置,此时属性变为"disabledbackground="。
②若控件command属性需要传参,可以使用lambda来传参。
import tkinter as tk
def text_config_change(check_flag,dynamic_entry):
if not check_flag.get():
dynamic_entry.config(disabledbackground='green')
dynamic_entry.config(state='disabled')
else:
dynamic_entry.config(background='yellow')
dynamic_entry.config(state='normal')
root_win = tk.Tk()
root_win.title('控件属性设置')
root_win.geometry('500x400')
check_flag = tk.BooleanVar()
check_button = tk.Checkbutton(root_win,text='是否同意',font=('Arial',11),variable=check_flag,command=lambda: text_config_change(check_flag, dynamic_entry))
check_button.place(x=100,y=200)
dynamic_entry = tk.Entry(root_win,state='disable',disabledbackground='green')
dynamic_entry.place(x=210,y=200,width=120)
root_win.mainloop()