任何人都可以指导我以下内容:
我想动态创建Entry小部件并分配分层名称(即e1,e2,e3 ......等),以便下一步轻松引用以收集信息。
请参阅下面的草稿代码,它无效
bowList = pd.DataFrame(np.empty([12,2]),columns=[['F','S']])
main2 = tki.Tk()
main2.minsize(800,500)
mb1 = tki.Menu(main2)
fm = tki.Menubutton(mb1)
l1 = tki.Label(main2, text="Fore Name")
l1.place(x=50,y=5,width=70)
l2 = tki.Label(main2, text="Surname")
l2.place(x=300,y=5,width=70)
h=1
for i in np.arange(1,12):
h = i * 30
tki.Label(main2, text=i).place(x=10,y=h,width=15)
e1 = tki.StringVar(main2)
e1 ="e1%i" %(i)
e2 = "e2%i" %(i)
print(e1), print(e2)
e1 = tki.Entry(main2, width=25, textvariable=e1)
e1.place(x=50,y=h)
e1.insert(i,i)
e2 = tki.Entry(main2, width=25)
e2.place(x=250,y=h)
def BowSave():
for i in np.arange(1,12):
#bowList.iloc[i,0] = (e11.get())
#bowList.iloc[i,1] = (e21.get())
#np.where(i == 10, print(bowList))
#print(main2.children.values())
#print(e11.get())
b1 = tki.Button(main2, text="Save", command=BowSave, height=2, width=5)
b1.place(x=500,y=5)
print(main2.winfo_name)
main2.mainloop()
谢谢, KP
答案 0 :(得分:0)
此代码段可能会帮助您入门。
...
entry_text = ['e1', 'e2', 'e3']
...
# add text entries
for x, text in enumerate(entry_text):
e = ttk.Entry(mFrame, width=80, name=text)
e.grid(column=1, row=x, sticky='WE', padx=5, pady=5)
e.insert(0, text)
...
e1Text = master.children['mFrame'].children['e1'].get()
e2Text = master.children['mFrame'].children['e2'].get()