-
Notifications
You must be signed in to change notification settings - Fork 0
/
Database-2.py
112 lines (90 loc) · 2.98 KB
/
Database-2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
from tkinter import *
from PIL import ImageTk, Image
import sqlite3
root = Tk()
root.title('DropDowns')
root.iconbitmap('./Icon_File.ico')
root.geometry('400x400')
#creating a database or connecting
#conn = sqlite3.connect('address_book.db')
#Create a cursor
#cur = conn.cursor()
#creating a table
#cur.execute(""" CREATE TABLE address(
# first_name text,
# last_name text,
# address text,
# city text,
# state text,
# zipcode integer
# )
# """)
#submit function
def submit():
#clear the text box
conn = sqlite3.connect('address_book.db')
cur = conn.cursor()
cur.execute("INSERT INTO address VALUES (:f_name, :l_name, :address, :city, :state, :zipcode)",
{
'f_name' : f_name.get(),
'l_name' : l_name.get(),
'address' : address.get(),
'city' : city.get(),
'state' : state.get(),
'zipcode' : zipcode.get()
}
)
conn.commit()
conn.close()
f_name.delete(0,END)
l_name.delete(0, END)
address.delete(0, END)
city.delete(0, END)
state.delete(0, END)
zipcode.delete(0,END)
#query to find the records
def query():
conn = sqlite3.connect('address_book.db')
cur = conn.cursor()
cur.execute("SELECT *,oid FROM address")
records = cur.fetchall()
print_records = ''
#loop through all results
for record in records:
print_records += str(record) + "\n"
query_label = Label(root,text=print_records)
query_label.grid(row=8, column=0, columnspan=2)
conn.commit()
conn.close()
f_name = Entry(root,width=30)
f_name.grid(row=0,column=1, padx=20)
l_name = Entry(root,width=30)
l_name.grid(row=1,column=1)
address = Entry(root,width=30)
address.grid(row=2,column=1)
city = Entry(root,width=30)
city.grid(row=3,column=1)
state = Entry(root,width=30)
state.grid(row=4,column=1)
zipcode = Entry(root,width=30)
zipcode.grid(row=5,column=1)
#create text box label
f_name_label = Label(root, text='First Name')
f_name_label.grid(row=0, column=0)
l_name_label = Label(root, text='Last Name')
l_name_label.grid(row=1, column=0)
address_label = Label(root, text='Address')
address_label.grid(row=2, column=0)
city_label = Label(root, text='City')
city_label.grid(row=3, column=0)
state_label = Label(root, text='State')
state_label.grid(row=4, column=0)
zipcode_label = Label(root, text='Zipcode')
zipcode_label.grid(row=5, column=0)
#create Submit button
submit_button = Button(root, text='Add Record', command=submit)
submit_button.grid(row=6, column=0, columnspan=2, pady=10, padx=10, ipadx=100)
#query button
query_button = Button(root, text='Show Records', command=query)
query_button.grid(row=7, column=0, columnspan=3, pady=10, padx=10, ipadx=100)
root.mainloop()