Wednesday, March 26, 2014

ANOTHER PROGRAM FOR WORK


from Tkinter import *
import sqlite3
#Witten by Steve Atchison For Shawnee County March 26 2014
def cleargui():
    textwindow.delete("1.0",END)
    addent.delete(0,END)
def connectdb():
    connect = sqlite3.connect("mydata.db")
    cur = connect.cursor()
    cur.execute("CREATE TABLE IF NOT EXISTS addressdata(address text)")
def addtodatabase():    
    theadd=addent.get()
    connect = sqlite3.connect("mydata.db")
    cur=connect.cursor()
    cur.execute("INSERT INTO addressdata VALUES(?)",([theadd.upper() + " - DELETED FROM GIS"]))
    connect.commit()
    getdata()
def getdata():
    connect = sqlite3.connect("mydata.db")
    cur=connect.cursor()
    thedata = cur.execute("SELECT * FROM addressdata")
    cleargui()
    for row in thedata:
        textwindow.insert("100.0",row[0]+"\n")
def findadd():
    cleargui()
    addr=findentry.get()
    connect = sqlite3.connect("mydata.db")
    cur=connect.cursor()
    thedata = cur.execute("SELECT * FROM addressdata WHERE address = ?",([addr]))
    for row in thedata:
        textwindow.insert("0.1",row[0])
    addent.delete(0,END)
def delrecord():
    addr=findentry.get()
    connect=sqlite3.connect("mydata.db")
    cur=connect.cursor()
    cur.execute("DELETE FROM addressdata WHERE address = ?",([addr]))
    connect.commit() #will not delete without this!
    cleargui()
    findentry.delete(0,END)
    getdata()

connectdb()#creates a database if none exists.

root=Tk()
root.title("REMOVED ADDRESS POINTS")
root.config(bg='black')
lbl=Label(root,text="ADDRESS TO REMVOE FROM GIS").pack()

menu2=Toplevel(root)
menu2.geometry('200x200')
menu2.config(bg="yellow")

addent=Entry(root,text="ADDRESS TO DELETE")
addent.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()

findentry=Entry(menu2)
findentry.pack()

btn4=Button(menu2,text="Find Address",command= findadd)
btn4.pack(padx=10,pady=10)

delbutton=Button(menu2,text='DELETE',command=delrecord)
delbutton.pack(padx=10,pady=10)

root.mainloop()


Followers

Blog Archive

About Me

My photo
Biking helps me to cope with life.