如何用 `for` 循环重写这段代码?
How to rewrite this code with `for` loop?
我有一个用 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")
我有一个用 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")