Tax Calculator--Tkinter

Someone Something fordhaivat at gmail.com
Mon Nov 9 01:22:16 CET 2009


I'm writing a simple tax calculator with Tkinter (just for fun).
Here's my current code:

from Tkinter import *;

class TaxCalc:
	def __init__(self, root):
		
		rate=Frame(root)
		rate.pack()

		income=Frame(root)
		income.pack()

		result=Frame(root)
		result.pack()

		self.rate=Entry(rate);
		self.rate.pack();
		self.enterr=Button(rate)	
		self.enterr['text']="Enter tax rate";
		self.enterr['command']=self.getRate;
		self.enterr.pack()

		self.income=Entry(income);
		self.income.pack();
		self.enteri=Button(income);
		self.enteri['text']="Enter income";
		self.enterr['command']=self.getIncome;
		self.enteri.pack();
		
		self.result=Entry(result);
		self.result.pack();
		self.entere=Button(result);
		self.entere['text']="Get result";
		self.entere['command']=self.printResult;
		self.entere.pack();

	def getRate(self):
		srate=self.rate.get();
		print "srate: ", srate;
	
	def getIncome(self):
		sincome=self.income.get();
		print "sincome: ", sincome;

	def printResult(self):
		if self.nrate is None | self.nincome is None:
			print "Clear everything and start again.";
			print "Don't fool around with me.";
		else:
			self.nresult=float(((100-self.nrate)/100)*self.nincome);
			self.result.insert(END, str(self.nresult));

root=Tk()
MyCalc=TaxCalc(root)
root.mainloop()

The thing is, that even if I put "12" in the result text field, get
returns an empty string. How can I fix this?



More information about the Python-list mailing list