Saturday, November 16, 2013

MY PROGRAM NOW SAVES TO A DATA BASE


from Tkinter import *
import sqlite3
#Witten by Steve Atchison 11/16/2013
def cleargui():
    textwindow.delete("1.0",END)
    deed.delete(0,END)

def connectdb():
    connect = sqlite3.connect("mydata.db")
    cur = connect.cursor()
    cur.execute("CREATE TABLE IF NOT EXISTS mytable(bookpage text, description text)")

def addtodatabase():
    deednum=deed.get()
    description=textwindow.get("1.0",END)
    connect = sqlite3.connect("mydata.db")
    cur=connect.cursor()
    cur.execute("INSERT INTO mytable VALUES(?,?)",([deednum,description]))
    connect.commit()
    cleargui()

def getdata():
    connect = sqlite3.connect("mydata.db")
    cur=connect.cursor()
    thedata = cur.execute("SELECT * FROM mytable")
    for row in thedata:
        textwindow.insert("100.0",row[0]+"\n"+row[1]+"\n")

connectdb()#creates a database if none exists.

root=Tk()
root.title("PROPERTY DESCRIPTION DATABASE")
root.config(bg='lightblue')
lbl=Label(root,text="Deed number").pack()
deed=Entry(root,text="Deed number")
deed.pack()

textwindow=Text(root,background='white')
textwindow.pack()

btn=Button(root,text='Add to Database ',command=addtodatabase)
btn.pack()

btn2=Button(root,text="Show data",command=getdata)
btn2.pack()

btn3=Button(root,text="Clear window",command=cleargui)
btn3.pack()
root.mainloop()

No comments:

Post a Comment

Followers

Blog Archive

About Me

My photo
Biking helps me to cope with life.