Saturday, October 23, 2010

My first data base connetion.

This is my first data base connection! I have a long way to go, but it is a start.

Thursday, October 21, 2010

Program I wrote for work


from Tkinter import *
import tkMessageBox
#Written by Shawnee County Mapping Department

def listfile():
   fob=open('BFEcalc.txt','r')
   textField.delete('1.0',END) #Clears text widget
   for eachline in fob:  
        textField.insert('1.0',eachline)
   fob.close()

def calcStream():
#Get data from entry widgets
    EL2=float(lowElevation.get())
    EL1=float(highElevation.get())
    D2=float(streamDist.get())
    D1=float(Measure.get())


    theRise = D1*((EL1-EL2)/D2)
    theBFE = theRise+EL2
  
#Clear entry widgets
    lowElevation.delete(0,END)
    highElevation.delete(0,END)
    streamDist.delete(0,END)
    Measure.delete(0,END)
#Open a file and write data to it

    if EL2 < EL1 and D2 > D1:
       
       
            fob=open("BFEcalc.txt","a")
            fob.write('-------------------------------\n')
            fob.write('Low elvevation = %s\n' % str(EL2))
            fob.write('High elevation = %s\n' % str(EL1))
            fob.write('Stream dist = %s\n' % str(D2))
            fob.write('Measure dist = %s\n' % str(D1))
            fob.write('The rise =  %s \n' % str(theRise))
            fob.write('The BFE = %s \n' % str(theBFE))
            fob.write('Address:%s '%propAdd.get()+'\n')
            fob.close()
            #tkMessageBox.showinfo(title='SNCO calculator',message="The BFE = %.3f \n The rise = %.3f" %(theBFE,theRise) )
            listfile()
            propAdd.delete(0,END)
    else:
        tkMessageBox.showerror(' ','Error in input data')
   
   
#GUI code
root = Tk()

root.geometry('200x400')
root.config(bg='blue')

Label(root,text='Higher elevation (EL 1)').pack(padx=5,pady=5)
highElevation = Entry()
highElevation.pack()

Label(root,text='Lower Elevation (EL 2)').pack(padx=5,pady=5)
lowElevation = Entry()
lowElevation.pack()

Label(root,text='Measurement (D 1)').pack(padx=5,pady=5)
Measure=Entry()
Measure.pack()

Label(root,text='Stream Distance (D 2)').pack(padx=5,pady=5)
streamDist=Entry()
streamDist.pack()

Label(root,text='Property address').pack(padx=5,pady=5)
propAdd=Entry(root)
propAdd.pack()

aButton=Button(root,text='Calculate',command=calcStream)
aButton.pack(padx=5,pady=5)

aButton2=Button(root,text='list file',command=listfile)
aButton2.pack()

textField=Text(root)
textField.pack(padx=2,pady=2)

root.mainloop()

Followers

Blog Archive

About Me

My photo
Biking helps me to cope with life.