I am implementing my first Tkinter UI using classes and I am facing some issues with the getter and setter of my Entry.
When I am trying to read the value of "N" i.e. self.nameVar.get()
, it prints nothing...
Could anyone point me in the right direction?
Many thanks in advance!
### Class PopUpScreen
class popUpScreen():
def __init__(self, newContact=True):
self.root2 = Tk()
self.root2.title('New Contact')
self.root2.resizable(False, False)
self.newContact = newContact
### Var
**self.nameVar = StringVar()**
### Widget
# Entry
self.entryFirstName = Entry(self.root2, **textvariable=self.nameVar**)
# Button
btnSave = ttk.Button(self.root2, text="Save", default="active", command=self.callbackSave).grid(row=9, column=3)
### Grid
# Entry
self.entryFirstName.grid(row=2, column=2, columnspan=2)
# Loop
self.root2.mainloop()
def callbackSave(self):
n = **self.nameVar.get()**
print('N value: ', n)
messagebox.showinfo( "Saving...", n))
self.root2.destroy()
### End Popup Contact class