I've made a simple registration form using tkinter and mongoengine.But due to some reason, the value grabbed from tkinter entry boxes are stored as null or empty in mongodb.I guess the problem is that the variable is not able to grab the value entered in the tkinter entry box, but I am not able to find a solution to this problem as the code looks syntactically correct.
from tkinter import *
import tkinter.messagebox
from mongoengine import *
connect('demo')
class Registration(Document):
username = StringField(required=True,unique=True)
password = StringField(required=True)
def register():
if len(Registration.objects(username=name)) == 1:
tkinter.messagebox.showinfo("Oops!", "Username already taken")
else:
entry = Registration(
username=name,
password=pwd
)
entry.save()
tkinter.messagebox.showinfo("Notice", "Registered Successfully !")
# GUI
root = Tk()
root.title("Registration Demo")
frame = Frame(root,width=500,height=500)
frame.pack()
label1 = Label(frame,text="username")
label2 = Label(frame,text="password")
entry1 = Entry(frame)
entry2 = Entry(frame)
name = entry1.get()
pwd = entry2.get()
button = Button(frame,text="Register",command=register)
label1.grid(row=0,column=0,sticky=E)
label2.grid(row=1,column=0,sticky=E)
entry1.grid(row=0,column=1)
entry2.grid(row=1,column=1)
button.grid(columnspan=2)
root.mainloop()
And here's the mongodb table view : Mongodb Output
As you can see in the output, the id is created but the username and password fields are blank, although the user had typed an input.