Programming Exercise 8.6 Add radio button options for filing
status to the tax calculator program of Project 1.
The user selects one of these options to determine the tax rate.
The Single option’s rate is 20%.
The Married option is 15%.
The Divorced option is 10%. The default
option is Single.
FYI this is not the answer
"""
File: taxformwithgui.py
Project 8.6
A GUI-based tax calculator.
Computes and prints the total tax, given the income and
number of dependents (inputs), and a standard deduction of
$10,000, an exemption amount of $3,000, and tax rates of
20% for Single
15% for Married
10% for Divorced
"""
from breezypythongui import EasyFrame
from breezypythonqui import HORIZONTAL
class TaxCalculator (EasyFrame):
def_init_(self) :
EasyFrame._init_(self, title="Tax
Calculator")
self.setsize (350, 200)
self.setResizable(False)
self.addlabel (text = "Gross Income",row = 0,column = 0)
self.income = self.addeloatField(value = 0.00, row = 0,
column
= 1, precision = 2)
self.addlabel (text = "Dependents", row = 1.
column = 0)
self.dependents
self.addIntegerfield(value = 0, row = 1, column = 1)
self.statusGroup = self.addRadiobuttonGroup(row = 2, column = 0,
rowspan = 1 columnspan = 3,orient = HORIZONTAL)
single = self. statusGroup.addRadiobutton(text ="Single")
self.statusGroup.addRadiobutton(text = "Married")
self.statusGroup.addRadiobutton(text = "Divorced")
self.statusGroup. setselectedButton (single)
self.addButton ("Compute", row = 3, column = 0, coluanspan = 3,
command = gelf.compute)
self.addlabel (text = "Total Tax" row = 4 , column = 0.)
self.totaltax = self.addfloatfield(value = 0.0, row = 4, column
= 1, precision = 2)
def compute (self):
standard_deduction = 10000.0
dependent_deduction = 3000.0
try:
numofDependents = self.dependents.getNumber()
grossincose = self.income.getNumber ()
status = self.statusGroup. getSelectedButton () ("text")
except ValueError: self.messageBox ("Error Message","Invalid
Input")
return
if status == "Single": rate = 0.20
elif status == "Married": rate == 0.15
elif status == "Divorced": rate =0.10
taxableIncome = grossincome
- standard deduction - (dependent deduction *
numofDependents
incomeTax = taxableIncome * rate
self.totalTax.setNumber(incomeTax)
def main():
TaxCalculator().mainloop()
if __name__ == "__main__":
main()
Programming Exercise 8.6 Add radio button options for filing status to the tax calculator program of Project 1. The user
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am