尊敬的先生
我有输入的网格(5行5列)
我尝试通过变量给特定单元格赋予值,请参阅我的代码
请指导我哪一个是正确的代码
entry(1,1).set_ value = 'testing data' grid(1,1).set_ value = 'testing data' root. grid[(1,1)].configure(text="the new text in specific cell ")
请告诉我如何将数据提供给特定单元格
这是我的代码:
from tkinter import *
root = Tk( )
def callback(*args):
print("testing data hi")
root.widget[(1,1)].configure(text="the new text in specific cell ")
root.bind("<F2>", callback)
b=0
for r in range(5):
for c in range(5):
b=b+1
Entry(root, text=str(b), borderwidth=1 ).grid(row=r,column=c)
root.mainloop()
def callback(*args):
EntryObjects = []
b=0
for r in range(5):
for c in range(5):
b=b+1
entry = Entry(root, borderwidth=1 )
entry.insert(0, b)
entry.grid(row=r,column=c)
EntryObjects.append(entry)
EntryObjects[1].insert(0, "text")
EntryObjects[4].insert(0, 'the new text in specific cell' )
callback()
root.mainloop()
还使用名称和 for 循环
def callback(*args):
b=0
for r in range(5):
for c in range(5):
b=b+1
entry = Entry(root, borderwidth=1, name=str(b))
entry.insert(0, b)
entry.grid(row=r,column=c)
for child in root.winfo_children():
if child.winfo_name() == '6':
child.insert(1, 'Entry was named 6')
callback()
root.mainloop()