Saturday, August 22, 2009

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()

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()

Followers

Blog Archive

About Me

My photo
Biking helps me to cope with life.