I want to create a form and read it's contents later currently I am thinking of writing something like this:
import tkinter as tk
objectkeylist=["name","lastname","age"]
root = tk.Tk()
textwidgetdict=dict()
textwidgetdict("name") =tk.Text(root, height=3, width=50)
textwidgetdict("lastname")=tk.Text(root, height=3, width=50)
textwidgetdict("age")=tk.Text(root, height=3, width=50)
textwidgetdict("name").pack()
textwidgetdict("lastname").pack()
textwidgetdict("age").pack()
def getcontent():
formcontentdict=dict()
formcontentdict("name") =textwidgetdict("name").get("1.0", tk.END)
formcontentdict("lastname") =textwidgetdict("lastname").get("1.0", tk.END)
formcontentdict("age") =textwidgetdict("age").get("1.0", tk.END)
return formcontentdict()
tk.mainloop()
Can I somehow reduce the redundant code with something like
map(lambda : objectlist[index]_text=objectlist.get("1.0", tk.END) , objectlist)
or
for object in objectlist:
object_text=objectlist.get("1.0", tk.END)
?
I don't even know what the correct keyword is to search for this.
I understand that the better idea ist to use the items of objectlist as keys for a dictionary like explained here: https://stackoverflow.com/a/4010869/3503111 I hope this code is more clear on what I want to achieve though