#!/usr/bin/python
#Gas mileage calculator written in version 2.6
#This program helps me keep track of my gas mileage!
from Tkinter import *
def calcMPG():
theGallons = galEntry.get()
theMiles = milesEntry.get()
milesPerGallon = float(theGallons)/float(theMiles),'miles per gallon'
print milesPerGallon
#open a file and write to it.
fob = open('Aveo_MPG.txt','a')
fob.write('------------------------------')
fob.write('\n')
fob.write(str(theGallons)+galEntry.get()+'\n')
fob.write('Miles = '+milesEntry.get()+'\n')
fob.write(str(milesPerGallon)+'\n')
fob.close
#Clear the entry widgets!
galEntry.delete(0,END)
milesEntry.delete(0,END)
#open Aveo_MPG file and list it. THIS WORKS GREAT!
def show():
fob = open('Aveo_MPG.txt','r')
for eachline in fob:
print eachline
fob.close()
root = Tk()
root.config(bg='blue')
aLable = Label(root,text="Miles")
aLable.pack()
galEntry = Entry(root)
galEntry.pack(padx=5,pady=5)
aLable2=Label(root,text="Gallons")
aLable2.pack()
milesEntry=Entry(root)
milesEntry.pack(padx=5,pady=5)
btn1= Button(root,text='Calc MPG', command = calcMPG)
btn1.pack(padx=5,pady=5)
btn2=Button(root,text='Show list',command=show)
btn2.pack(padx=5,pady=5)
root.mainloop()
No comments:
Post a Comment