如何用"for"循环重写此代码



我用tkinter创建了一个单选按钮,单选按钮的命令是:

def FieldsetChanger ():
lbl1_1.configure(state="enable")
Entry1_1.configure(state="enable")
lbl2_1.configure(state="enable")
Entry2_1.configure(state="enable")

我可以用for循环重写这个函数吗?

您可以将这些元素存储在数组(例如列表(中并对其进行迭代:

my_arr = [lbl1_1, Entry1_1, lbl2_1, Entry2_1]
def FieldsetChanger ():
for element in my_arr:
element.configure(state="enable")

最新更新