This is my first data base connection! I have a long way to go, but it is a start.
This is a personal record of my python programming experiences. It will allow me to see how I am progressing as I learn a new language.
Saturday, October 23, 2010
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()
Subscribe to:
Posts (Atom)
Followers
Blog Archive
- June (1)
- March (3)
- February (1)
- July (3)
- May (1)
- April (1)
- March (1)
- January (1)
- December (1)
- November (4)
- July (3)
- May (2)
- April (1)
- March (6)
- February (2)
- December (1)
- November (1)
- September (3)
- August (3)
- July (1)
- March (3)
- January (1)
- December (5)
- November (2)
- October (1)
- September (2)
- August (1)
- July (4)
- May (3)
- February (1)
- January (1)
- December (1)
- November (2)
- October (2)
- September (9)
- August (2)
- May (1)
- April (1)
- March (6)
- February (5)
- January (3)
- August (2)