This is a program that I use at work. It makes my life a lot easier. I shared it with my co-workers too. Its a simple converter tool. I wrote it at home, and then emailed it to my workplace. When I paste this into my blog, it removes the indentation. Very annoying. Python requires indentation in its blocks of code.
#Written by Steve Atchison April 6 2009
from Tkinter import *
import webbrowser
import tkSimpleDialog
def ConvertChains(): #Function to convert Chains to feet
chains = tkSimpleDialog.askstring('Chain converter','Enter Chains ')
print( chains, 'chains = ',round((float(chains) * 66),2),'ft')
def ConvertRods(): #Function to convert rods to feet
theRods = tkSimpleDialog.askstring('Rod converter','Enter rods ')
print( theRods, 'Rods =',round(( float(theRods) * 16.5),2), 'ft')
def unknownside(): #Function to calculate unkown side of a parcel
knownSide = tkSimpleDialog.askstring('Enter known side','known side?')
acres = tkSimpleDialog.askstring('Enter acres','Acres?')
print( 'Unknown side = ', round((float(acres)* 43560) /float(knownSide),2), " ft")
def SncoWeb():
webbrowser.open('http://www.snco.us/')
open
#Create buttons then pack them into a window
root = Tk()
#aName = tkSimpleDialog.askstring('the title','enter text',)
ConChains = Button(root,text='Convert Chains', command = ConvertChains)
ConRods = Button(root,text='Convert Rods ', command = ConvertRods)
FindUnknown = Button(root, text="Unknown Side ", command=unknownside)
SNCO = Button(root, text='Open SNCO', command = SncoWeb)
SNCO.pack()
ConChains.pack()
ConRods.pack()
FindUnknown.pack()
#exitbutton.pack()
root.mainloop()
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, August 22, 2009
Wednesday, August 19, 2009
I created this Blog to help me keep track of my progress as I learn the Python programing language. For me, it has been a slow process. I wrote a simple gas mileage calculator, and for me it is a mile stone. I like GUI's, so I added some Tkinter code. I also added a button that will save the data to a text file object. I learn a lot from watching youtube videos, but I have some good books too. I program for a hobby, and it helps me understand how computers work, plus I think that its good for my brian. I am currently using version 2.6, mainly because Tkinter works different in 3.
#Simple gas mileage calculator by Steven Atchison 8/18/09
from Tkinter import *
def showMPG():
print(mpg)
def MilageCalc():
theGals = input("Gallons? ")
Odometer = input("Miles? ")
mpg= (float(Odometer) / float(theGals))
print('Miles per gallon = %f'%mpg )
#Open a textfile (a file object) and save
def Saveit():
aFileObject = open('AveoMPG.txt','a')
aFileObject.writelines(str(mpg)+ '\n')
aFileObject.close()
root = Tk()
aButton = Button(root,text = 'Gas mileage calculator',command = MilageCalc).pack()
saveBtn = Button(root,text = 'Save', command = Saveit).pack()
stopBtn = Button(root,text = 'Close program ', command = quit).pack()
testbtn = Button(root,text = 'print mpg', command = showMPG).pack()
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)