Jason (toomanywhispers) wrote in littlescripts,
Jason
toomanywhispers
littlescripts

A program to figure sales tax.

I took the groundwork I laid for my converter program and used it to write a program for calculating sales tax. Very little of the converter code survived the rewriting I did to incoporate grid managing of the different widgets. It looks a heck of alot more polished than Converter because of the grid managing.



# NYstax 0.1.0
# Created by Jason Capron
# Licenced under the GPL (Check your Python folder, including it here would be like appending a dictionary to a post-it note)
.
from Tkinter import *
root=Tk()
.
def but1():
....a=float(v.get())
....a2 = a*.08
....b = (a+a2)
....w.delete(1.0,END)
....print w.insert(INSERT,a2)
....y.delete(1.0,END)
....print y.insert(INSERT,b)
.
v = StringVar()
w = Text(root,height=1, width=20)
w.grid(row=1, column=1)
TaxLab = Label(root, text="Tax")
TaxLab.grid(row=1, column=0)
y = Text(root, height=1, width=20)
y.grid(row=2, column=1)
TotLab = Label(root, text="Total with Tax")
TotLab.grid(row=2, column=0)
x = Label(root, text="Amount to convert")
x.grid(row=0, column=0)
e = Entry(root,textvariable=v, width=20)
e.grid(row=0,column=1)
b1 = Button(root,text="Calculate sales tax",command=but1)
b1.grid(row=3,columnspan=3)
.
root.mainloop()



What gave me migranes was getting the button to work after adding the grid code.
I was lumping things together like this

"b1 = Button(root,text="Calculate sales tax",command=but1).grid(row=3,columnspan=3)"

Instead of using two lines like this,

"b1 = Button(root,text="Calculate sales tax",command=but1)
b1.grid(row=3,columnspan=3)"


To modify this scipt for your own state sales tax, just change "a2 = a*.08" (Line 11) to whatever the rate for sales tax is in your area. New Yorks is 8%, so the mulitplyer is .08
  • Post a new comment

    Error

    default userpic
  • 2 comments