Hi,
i am trying to write a code for an assignment that uses tkinter for the GUI and SQL to save the data.
here is the annoying bit of code.
cur.execute("INSERT INTO user (ID, Name, Age, Email, Town) VALUES (?, ?, ?, ?, ?)",
(uid, str(nme), str(age), str(eml), str(twn)))
and here is the error i get
Exception has occurred: NameError
name 'uid' is not defined
the thing is that i have already defined all the names in a function.
here is my full code
from tkinter import *
import sqlite3
con = sqlite3.connect("user_info.db")
cur = con.cursor()
root = Tk()
root.title("create account")
def get_input():
uid = e0.get()
nme = e1.get()
age = e2.get()
eml = e3.get()
twn = e4.get()
e0.delete("0", "end")
e1.delete("0", "end")
e2.delete("0", "end")
e3.delete("0", "end")
e4.delete("0", "end")
print(uid)
print(nme)
print(age)
print(eml)
print(twn)
lbl = Label(root, text= "ID: ")
lbl.grid(row="0", column="0")
e0 = Entry(root, width= 30)
e0.grid(row="0", column="1")
lbl1 = Label(root,text= "Name: ")
lbl1.grid(row="2",column="0")
e1 = Entry(root, width = 30)
e1.grid(row="2",column="1")
lbl2 = Label(root, text = "Age: ")
lbl2.grid(row="4",column="0")
e2 = Entry(root, width = 30)
e2.grid(row="4",column="1")
lbl3 = Label(root, text = "Email: ")
lbl3.grid(row="6",column="0")
e3 = Entry(root, width = 30)
e3.grid(row="6",column="1")
lbl4 = Label(root, text = "Town: ")
lbl4.grid(row="8",column="0")
e4 = Entry(root, width = 30)
e4.grid(row="8",column="1")
sbut = Button(root, text= "submit", command = get_input)
sbut.grid(row="9",column="1")
root.geometry("300x300")
root.mainloop()
cur.execute("INSERT INTO user (ID, Name, Age, Email, Town) VALUES (?, ?, ?, ?, ?)",
(uid, str(nme), str(age), str(eml), str(twn)))
con.commit()
con.close()```
can someone help