I have created a namedtuple like this.
Named_Tuple_1 = namedtuple("Coordinates", ["x", "y", "z"], verbose=False, rename=False)
Point_1 = Named_Tuple_1(x=1, y=1, z=1)
Point_2 = Named_Tuple_1(x=2, y=2, z=2)
Point_3 = Named_Tuple_1(x=3, y=3, z=3)
I can access values easily like this.
Point_2.x
But when I try to get Point_2 from an entry box I get this error.
AttributeError: 'str' object has no attribute 'x'
So I learned that entry boxes return string values.
How can I get a namedtuple value from a string?
String_1 = "Point_2"
String_1 ???
Thanks.
Sorry for the confusion. Hope this is more clear.
So here I decided to add Point_1.x with Point_2.x and add the total to my Dialog as a label.
Named_Tuple_1 = namedtuple("Coordinates", ["x", "y", "z"], verbose=False, rename=False)
Point_1 = Named_Tuple_1(x=1, y=2, z=3)
Point_2 = Named_Tuple_1(x=4, y=5, z=6)
Point_3 = Named_Tuple_1(x=7, y=8, z=9)
def ADD_x_1():
Sum_of_x = Point_1.x + Point_2.x
My_Label_1 = Label(Dialog, text=Sum_of_x)
My_Label_1.pack()
Dialog = Tk()
My_Button_1 = Button(Dialog, text="Add x Value", command=ADD_x_1)
My_Button_1.pack()
Dialog.mainloop()
Now I want to do the same thing but have a user decide which point to add.
def ADD_x_2():
First_Point_x = My_Entry_1.get().x
Second_Point_x = My_Entry_2.get().x
Sum_of_x = First_Point_x + Second_Point_x
My_Label_3 = Label(Dialog, text=Sum_of_x)
My_Label_3.pack()
Dialog = Tk()
My_Label_1 = Label(Dialog, text="Select first point")
My_Label_1.pack()
My_Entry_1 = Entry(Dialog, bd=2, width=10)
My_Entry_1.pack()
My_Label_2 = Label(Dialog, text="Select second point")
My_Label_2.pack()
My_Entry_2 = Entry(Dialog, bd=2, width=10)
My_Entry_2.pack()
My_Button_2 = Button(Dialog, text="Add x Value", command=ADD_x_2)
My_Button_2.pack()
Dialog.mainloop()
My problem is that My_Entry_1.get() and My_Entry_2.get() are strings. And I get the error AttributeError: 'str' object has no attribute 'x'.
So my question was how can I take the string from My_Entry_1 and My_Entry_2 to access the x values?
Sorry again for the confusion.
Thanks.