我想用一个for循环创建按钮,并输入(状态=禁用)部件。要创建的小部件的数量将是运行时参数。我想要的是,每次点击按钮时,相应的条目都会启用(state =“normal”)。在我的代码中的问题是,我点击的任何按钮,它只影响最后一个条目小部件。有没有什么办法解决这一问题。?这里是我的代码:在你的代码如何链接在for循环中创建的python tkinter小部件?
from tkinter import *
class practice:
def __init__(self,root):
for w in range(5):
button=Button(root,text="submit",
command=lambda:self.enabling(entry1))
button.grid(row=w,column=0)
entry1=Entry(root, state="disabled")
entry1.grid(row=w,column=1)
def enabling(self,entryy):
entryy.config(state="normal")
root = Tk()
a = practice(root)
root.mainloop()
哇。这解决了我的问题!谢谢! – Crstn
@Crstn请注意,我说的第一点(在我的回答中)很重要。否则,你最终会陷入神秘的错误。 –