Challenge

Project 2 - EDA on Vehicle Insurance Customer Data

from tkinter import *
import sqlite3
import tkinter.ttk as ttk
import tkinter.messagebox as tkMessageBox

root = Tk()
root.title('customer data')

def Database():
global conn,cursor
conn = sqlite3.connect('customer_policy.db')
cursor =conn.cursor()
cursor.execute(" CREATE A TABLE IF NOT EXISTS member(mem_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,customer_id REAL,age REAL,driving license present TEXT,reagion code REAL,previously insured TEXT,veicle age TEXT,vehicle damage TEXT)")


def Create():
if CUSTOMER_ID.get() == "" or AGE.get() == "" or GENDER.get() == "" or DRIVINGLICENCEPRESENT.get() == "" or REGIONCODE.get() == "" or PREVIOUSLYINSURED.get() == "" or VEHICLEAGE.get() == "" or VEHICLEDAMAGE.get() == "":
txt_result_config(text ="Please enter allthe fields",fd="red")

else:
Database()
cursor.execute("INSERT INTO member(customer_id,age,gender,driving license present,region code,previously insured,vehicle age,vehicle damage) VALUES(?,?,?,?,?,?,?,?,)",str(CUSTOMER_ID.get()),str(GENDER.get()),str(AGE.get()),str(DRIVINGLICENCEPRESENT.get()),str(REGIONCODE.get()),str(PREVIOUSLYINSURED.get()),str(VEHICLEAGE.get()),str(VEHICLEDAMAGE.get())
conn.commit()
CUSTOMER_ID.set("")
AGE.set("")
GENDER.set("")
DRIVINGLICENSEPRESENT.set("")
REGIONCODE.set("")
PREVIOUSLY INSURED.set("")
VEHICLEAGE.set("")
VEHIHLEDAMAGE.set("")
cursor.close()
conn.close()
txt_result.config(text="Record inserted !",fg="green")

def Read():
tree.delete(*tree.get_children)
Database()
cursor.execute("SELECT * FROM member ORDER BY age ASC")
fetch = cursor.fetchall()
for data in fetch:
tree.insert('','end',values=(data[1],data[2],data[3],data[4],data[5],data[6],data[7],data[8]))
cursor.close()
txt_result.config(text="Successfully fetched data !",fg="black")

def Exit():
result = tkMessageBox.askquestion("Do you want to exit ? (y/n)", icon = "Warning")
if result == yes:
root.destroy()
exit()

CUSTOMER_ID = StringVar()
AGE= StringVar()
GENDER = StringVar()
DRIVINGLICENSEPRESENT = StringVar()
REGIONCODE = StringVar()
PREVIOUSLYINSURED = StringVar()
VEHICLEAGE.set() = StringVar()
VEHICLEDAMAGE.set() = StringVar()

#Frame

Top = Frame(root, width=900,height=50,bd=8,relief='raise')
Top.pack(side=TOP)
Left = Frame(root, width=300,height=500,bd=8,relief='raise')
Left.pack(side=LEFT)
Right = Frame(root, width=600,height=500,bd=8,relief='raise')
Right.pack(side=RIGHT)


Forms = Frame(Left, width=300,height=450)
Forms.pack(side=TOP)

Buttons = Frame(Left,width=300,height=100,bd=8,relief='raise')
Buttons.pack(side=BOTTOM)

#Lables

txt_title=Label(Top, width=900,text='customer data')


#===========================LABEL WIDGET============================================================
txt_title = Label(Top, width=900, font=('arial', 24), text = "customer data application")
txt_title.pack()
txt_customer_id = Label(Forms, text="Customer_id:", font=('arial', 16), bd=15)
txt_customer_id.grid(row=0, stick="e")
txt_age = Label(Forms, text="Age:", font=('arial', 16), bd=15)
txt_age.grid(row=1, stick="e")
txt_gender = Label(Forms, text="Gender:", font=('arial', 16), bd=15)
txt_gender.grid(row=2, stick="e")
txt_drivinglicencepresent = Label(Forms, text="Drivinglicencepresent:", font=('arial', 16), bd=15)
txt_drivinglicencepresent.grid(row=3, stick="e")
txt_regioncode = Label(Forms, text="Regioncode:", font=('arial', 16), bd=15)
txt_regioncode.grid(row=4, stick="e")
txt_previouslyinsured = Label(Forms, text="Previouslyinsured:", font=('arial', 16), bd=15)
txt_previouslyinsured.grid(row=5, stick="e")
txt_vehicleage = Label(Forms, text="Vehicleage:", font=('arial', 16), bd=15)
txt_vehicleage.grid(row=6, stick="e")
txt_vehicledamage = Label(Forms, text="Vehicledamage:", font=('arial', 16), bd=15)
txt_vehicledamage.grid(row=7, stick="e")
txt_result = Label(Buttons)
txt_result.pack(side=TOP)

#============================ENTRY WIDGET==================================================================
customer_id = Entry(Forms, textvariable=CUSTOMER_ID, width=30
customer_id.grid(row=0, column=1)
age = Entry(Forms, textvariable=AGE, width=30)
age.grid(row=1, column=1)
gender = Entry(Forms, textvariable=GENDER, width=30)
gender.grid(row=2, column=1)
drivinglicencepresent = Entry(Forms, textvariable=DRIVINGLICENCEPRESENT, width=30)
drivinglicencepresent.grid(row=3, column=1)
regioncode = Entry(Forms, textvariable=REGIONCODE, width=30)
regioncode.grid(row=4, column=1)
previouslyinsured = Entry(Forms, textvariable=PREVIOUSLYINSURED, width=30)
previouslyinsured.grid(row=5, column=1)
vehicleage = Entry(Forms, textvariable=VEHICLEAGE, width=30)
vehicleage.grid(row=6, column=1)
vehicledamage = Entry(Forms, textvariable=VEHICLEDAMAGE, width=30)
vehicledamage.grid(row=7, column=1)


#===========================BUTTONS WIDGET==========================================================
btn_create = Button(Buttons, width=10, text="Create", command=Create)
btn_create.pack(side=LEFT)
btn_read = Button(Buttons, width=10, text="Read", command=Read)
btn_read.pack(side=LEFT)
btn_update = Button(Buttons, width=10, text="Update", state=DISABLED)
btn_update.pack(side=LEFT)
btn_delete = Button(Buttons, width=10, text="Delete", state=DISABLED)
btn_delete.pack(side=LEFT)
btn_exit = Button(Buttons, width=10, text="Exit", command=Exit)
btn_exit.pack(side=LEFT)

#==========================LIST WIDGET======================================================
scrollbary = Scrollbar(Right, orient=VERTICAL)
scrollbarx = Scrollbar(Right, orient=HORIZONTAL)

tree = ttk.Treeview(Right, columns=("customer_id,age,gender,drivinglicensepresent,regioncode,previouslyinsured,vehicleage,vehicle damage"))

scrollbary.config(command=tree.yview)
scrollbary.pack(side=RIGHT, fill=Y)
scrollbarx.config(command=tree.xview)
scrollbarx.pack(side=BOTTOM, fill=X)
tree.heading('customer_id', text="customer_id", anchor=W)
tree.heading('age', text="age", anchor=W)
tree.heading('gender', text="gender", anchor=W)
tree.heading('drivinglicensepresent', text="drivinglicensepresent", anchor=W)
tree.heading('regioncode', text="regioncode", anchor=W)
tree.heading('previouslyinsured', text="previouslyinsured", anchor=W)
tree.heading('vehicleage', text="vehicleage", anchor=W)
tree.heading('vehicledamage', text="vehicledamage", anchor=W)
tree.column('#0', stretch=NO, minwidth=0, width=0)
tree.column('#1', stretch=NO, minwidth=0, width=120)
tree.column('#2', stretch=NO, minwidth=0, width=150)
tree.column('#3', stretch=NO, minwidth=0, width=120)
tree.column('#4', stretch=NO, minwidth=0, width=100)
tree.column('#5', stretch=NO, minwidth=0, width=120)
tree.column('#6', stretch=NO, minwidth=0, width=100)
tree.column('#7', stretch=NO, minwidth=0, width=120)
tree.pack()

#===============================INITIALIZATION===================================================
if __name__ == '__main__':
root.mainloop()

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.