You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

163 lines
3.6 KiB

from tkinter import *
from tkinter import ttk
from tkinter import messagebox
from tkinter import filedialog
from PIL import ImageTk, Image
import sqlite3
import os
###########
#VARIBALES#
###########
colorBackgroundRoot="#06283D"
########
#WINDOW#
########
root = Tk()
root.title("Database Interface")
root.attributes('-type', 'dialog')#https://stackoverflow.com/questions/35830851/how-to-make-tkinter-window-floating-in-i3-windowmanager
root.geometry("1000x1000")
root.config(bg=colorBackgroundRoot)
#############
#DEFINITIONS#
#############
def dbSubmit():
#Connect to database
db = sqlite3.connect('address_book.db')
#Create Cursor
c = db.cursor()
c.execute("INSERT INTO addresses VALUES (:firstName, :lastName, :address, :city, :state, :zipCode)",
{
'firstName' : firstName.get(),
'lastName' : lastName.get(),
'address' : address.get(),
'city' : city.get(),
'state' : state.get(),
'zipCode' : zipCode.get()
})
#Save chnages to the database
db.commit()
#Close Connection
db.close()
# Clear the text Boxes
firstName.delete(0,END)
lastName.delete(0,END)
address.delete(0,END)
city.delete(0,END)
state.delete(0,END)
zipCode.delete(0,END)
def dbQuery():
#Connect to database
db = sqlite3.connect('address_book.db')
#Create Cursor
c = db.cursor()
c.execute("SELECT *, oid FROM addresses")
records = c.fetchall();
print(records)
print_records=''
for record in records:
print_records += str(record) + '\n'
labelQuery = Label(root, text=print_records)
labelQuery.grid(row=8, column=0, columnspan=2)
#Save chnages to the database
db.commit()
#Close Connection
db.close()
#########
#DATBASE#
#########
#Create Table
'''
c.execute("""CREATE TABLE addresses (
first_name text,
last_name text,
address text,
city text,
state text,
zipcode integer
)
""")
'''
################
#IMAGES & ICONS#
################
###########
#FUNCTIONS#
###########
########
#FRAMES#
########
#########
#WIDGETS#
#########
firstName = Entry(root,width=30)
lastName = Entry(root,width=30)
address = Entry(root,width=30)
city = Entry(root,width=30)
state = Entry(root,width=30)
zipCode = Entry(root,width=30)
firstNameLabel = Label(root,text="First Name: ")
lastNameLabel = Label(root,text="Last Name: ")
addressLabel = Label(root,text="Address: ")
cityLabel = Label(root,text="city: ")
stateLabel = Label(root,text="state: ")
zipCodeLabel = Label(root,text="Zip Code: ")
buttonSubmit = Button(root, text="add to db", command=dbSubmit)
buttonQuery = Button(root, text="request from db", command=dbQuery)
###########
#PLACEMENT#
###########
firstName.grid(row=0, column=1, padx=20)
firstNameLabel.grid(row=0, column=0)
lastName.grid(row=1, column=1, padx=20)
lastNameLabel.grid(row=1, column=0)
address.grid(row=2, column=1, padx=20)
addressLabel.grid(row=2, column=0)
city.grid(row=3, column=1, padx=20)
cityLabel.grid(row=3, column=0)
state.grid(row=4, column=1, padx=20)
stateLabel.grid(row=4, column=0)
zipCode.grid(row=5, column=1, padx=20)
zipCodeLabel.grid(row=5, column=0)
buttonSubmit.grid(row=6, column=0, columnspan=2, padx=10, pady=10, ipadx=100)
buttonQuery.grid(row=7, column=0, columnspan=2, padx=10, pady=10, ipadx=100)
############
#DISPLAYING#
############
#Showing on the screen and aranging them
#Main Loop Equivalent of our main();
root.mainloop()