This is the code I am working on. In the section where I create the sumbit function, I try to use the .get() function however it does not work. This code is for my assessment I am currently doing and it is due in a month. I have been watching tkinter videos on youtube to try and get an idea of what I am doing but after rewatching the video I can not find any differences between my code and his. The link to the video is https://www.youtube.com/watch?v=YR3h2CY21-U&list=PLCC34OHNcOtoC6GglhF3ncJ5rLwQrLGnV&index=19. I am up to 12 minutes and 50 seconds.
from tkinter import *
import sqlite3
root = Tk()
# root.geometry("800x500")
# Databases
# Create a database or connect to one
conn = sqlite3.connect('incidents.db')
# create a cursor
c = conn.cursor()
# Create table
'''c.execute("""CREATE TABLE incidents (
first_name text,
last_name text,
address text,
city text,
state text,
zipcode integer
)""")'''
# Create Submit Function For database
def submit():
# Create a database or connect to one
conn = sqlite3.connect('incidents.db')
# Create cursor
c = conn.cursor()
# Insert Into Table
c.execute("INSERT INTO incidents VALUES (:name, :date, :address, :city, :state, :zipcode)",
{
'name': Name.get(),
'date': date.get(),
'address': address.get(),
'city': city.get(),
'state': state.get(),
'zipcode': zipcode.get()
})
# Commit Changes
conn.commit()
# Close Connection
conn.close()
# Clear The Text Boxes
Name.delete(0, END)
date.delete(0, END)
address.delete(0, END)
city.delete(0, END)
state.delete(0, END)
zipcode.delete(0, END)
# Create Text Boxes
Name = Entry(root, width=30).grid(row=0, column=1, padx=20, pady=(10, 0))
date = Entry(root, width=30).grid(row=0, column=3)
address = Entry(root, width=30).grid(row=0, column=5)
city = Entry(root, width=30).grid(row=0, column=7)
state = Entry(root, width=30).grid(row=1, column=1)
zipcode = Entry(root, width=30).grid(row=1, column=3)
delete_box = Entry(root, width=30).grid(row=1, column=5, pady=5)
# Create Text Box Labels
name_label = Label(root, text="Name").grid(row=0, column=0, pady=(10, 0))
date_label = Label(root, text="Last Name").grid(row=0, column=2)
address_label = Label(root, text="Address").grid(row=0, column=4)
city_label = Label(root, text="City").grid(row=0, column=6)
state_label = Label(root, text="State").grid(row=1, column=0)
zipcode_label = Label(root, text="Zipcode").grid(row=1, column=2)
delete_box_label = Label(root, text="Select ID").grid(row=1, column=4, pady=5)
# Create Submit Button
submit_btn = Button(root, text="Add Record To Database", command=submit)
submit_btn.grid(row=6, column=0, columnspan=2, pady=10, padx=10, ipadx=100)
# Commit Changes
conn.commit()
# Close Connection
conn.close()
root.mainloop()
When I run the code I get this error message:
Exception in Tkinter callback
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter/__init__.py", line 1699, in __call__
return self.func(*args)
File "/Users/School/PycharmProjects/HelloWorld/Databases.py", line 39, in submit
'name': Name.get(),
AttributeError: 'NoneType' object has no attribute 'get'
If someone can help me it would be greatly appreciated.