实验语言:Python
实验界面搭建:利用tkinter搭建图形化界面
实验目的:搭建方便使用的计算个人所得税的计算器
参考:https://m.taxspirit.com(个税精灵:计算个人所得税在线计算器)
计算器应用到的计算公式如下:
搭建的计算器截图如下:
进入界面:
计算结果界面如下:
使用说明:用户选择当前月份,并输入本月税前工资、本月五险一金以及专项附加扣除费用。点击计算即可得到相应的结果。
代码如下:
from tkinter import * from tkinter import ttk import tkinter.messagebox def click(): if not salary.get(): tkinter.messagebox.showwarning('警告','请输入本月税前工资!') elif not safe.get(): tkinter.messagebox.showwarning('警告','请输入五险一金!') elif not cost.get(): tkinter.messagebox.showwarning('警告','请输入专项附加扣除!') else: la.destroy() tree.destroy() reason = Label(root, text="计算结果",width=20, height=2) reason.grid(row=5, columnspan=4) month_get = float(fruit.get()) salary_get = float(salary.get()) safe_get = float(safe.get()) cost_get = float(cost.get()) salary_sum = month_get * salary_get Label(root, text="累计收入:",width=20, height=2).grid(row=7, column=0) Label(root, text="{}".format(salary_sum),width=20, height=2).grid(row=7, column=1) safe_sum = month_get * safe_get Label(root, text="累计五险一金:",width=20, height=2).grid(row=7, column=2) Label(root, text="{}".format(safe_sum),width=20, height=2).grid(row=7, column=3) cost_sum = month_get * cost_get Label(root, text="累计专项附加扣除:",width=20, height=2).grid(row=8, column=0) Label(root, text="{}".format(cost_sum),width=20, height=2).grid(row=8, column=1) sum_fee = 5000 Label(root, text="累计减除费用:",width=20, height=2).grid(row=8, column=2) Label(root, text="{}".format(sum_fee),width=20, height=2).grid(row=8, column=3) tax_should_pay = salary_sum - safe_sum - cost_sum - 5000 if tax_should_pay < 0: tax_should_pay = 0 Label(root, text="应纳税所得额:",width=20, height=2).grid(row=9, column=0) Label(root, text="{}".format(tax_should_pay),width=20, height=2).grid(row=9, column=1) if tax_should_pay <= 36000: tax_rate = 0.03 quicknum = 0 elif 36000 < tax_should_pay <= 144000: tax_rate = 0.1 quicknum = 2520 elif 144000 < tax_should_pay <= 300000: tax_rate = 0.2 quicknum = 16920 elif 300000 < tax_should_pay <= 420000: tax_rate = 0.25 quicknum = 31920 elif 420000 < tax_should_pay <= 660000: tax_rate = 0.3 quicknum = 52920 elif 660000 < tax_should_pay <= 960000: tax_rate = 0.35 quicknum = 85920 else: tax_rate = 0.45 quicknum = 181920 Label(root, text="税率:",width=20, height=2).grid(row=9, column=2) Label(root, text="{}".format(tax_rate),width=20, height=2).grid(row=9, column=3) Label(root, text="速算扣除数:",width=20, height=2).grid(row=10, column=0) Label(root, text="{}".format(quicknum),width=20, height=2).grid(row=10, column=1) last_month_salary_sum = salary_sum - salary_get last_month_safe_sum = safe_sum - safe_get last_month_cost_sum = cost_sum - cost_get last_month_tax_should_pay = last_month_salary_sum - last_month_safe_sum - last_month_cost_sum if last_month_tax_should_pay <= 36000: last_tax_rate = 0.03 last_quicknum = 0 elif 36000 < last_month_tax_should_pay <= 144000: last_tax_rate = 0.1 last_quicknum = 2520 elif 144000 < last_month_tax_should_pay <= 300000: last_tax_rate = 0.2 last_quicknum = 16920 elif 300000 < last_month_tax_should_pay <= 420000: last_tax_rate = 0.25 last_quicknum = 31920 elif 420000 < last_month_tax_should_pay <= 660000: last_tax_rate = 0.3 last_quicknum = 52920 elif 660000 < last_month_tax_should_pay <= 960000: last_tax_rate = 0.35 last_quicknum = 85920 else: last_tax_rate = 0.45 last_quicknum = 181920 sum_tax_should_pay = tax_should_pay * tax_rate - quicknum Label(root, text="累计应纳税额:",width=20, height=2).grid(row=10, column=2) Label(root, text="{}".format(sum_tax_should_pay),width=20, height=2).grid(row=10, column=3) sum_tax_payed = last_month_tax_should_pay * last_tax_rate - last_quicknum Label(root, text="累计已缴税额:",width=20, height=2).grid(row=11, column=0) Label(root, text="{}".format(sum_tax_payed),width=20, height=2).grid(row=11, column=1) this_month_pay = sum_tax_should_pay - sum_tax_payed Label(root, text="当月应纳税额:",width=20, height=2).grid(row=11, column=2) Label(root, text="{}".format(this_month_pay),width=20, height=2).grid(row=11, column=3) really_salary = salary_get - safe_get - this_month_pay Label(root, text="本月税后工资:",width=20, height=2).grid(row=12, column=0) Label(root, text="{}".format(really_salary),width=20, height=2).grid(row=12, column=1) root = Tk() root.title('个人所得税计算器') root.geometry('%dx%d' % (600, 600)) Label(root, text="工资累计预缴个税计算器",width=20, height=2).grid(row=0, columnspan=4) items = [1,2,3,4,5,6,7,8,10,11,12] Label(root, text="当前月份:",width=20, height=2).grid(row=1, column=0) fruit = StringVar() fruit.set(items[6]) menu = OptionMenu(root, fruit, *items) menu.grid(row=1, column=1) Label(root, text="本月税前工资:",width=20, height=2).grid(row=1, column=2) salary = Entry(root) salary.grid(row=1, column=3) Label(root, text="五险一金:",width=20, height=2).grid(row=2, column=0) safe = Entry(root) safe.grid(row=2, column=1) Label(root, text="专项附加扣除:",width=20, height=2).grid(row=2, column=2) cost = Entry(root) cost.grid(row=2, column=3) Label(root, text="五险一金由个人缴纳部分与公司缴纳部分组成,具体数值请移至五险一金计算窗口计算").grid(row=3, columnspan=4) Label(root, text="减除费用(起征点):",width=20, height=2).grid(row=4, column=0) Label(root, text="5000元",width=20, height=2).grid(row=4, column=1) Button(root, text="计算",command=click ,width=50, height=2).grid(row=5, columnspan=4) la = Label(root, text="工收入个税资薪金",width=20, height=2) la.grid(row=6, columnspan=4) tree = ttk.Treeview(root) tree["columns"] = ('累计预扣预缴应纳税所得额','预扣税率','速算扣除数') tree.column("累计预扣预缴应纳税所得额", width=250) tree.column("预扣税率", width=60) tree.column("速算扣除数", width=60) tree.heading("累计预扣预缴应纳税所得额", text="累计预扣预缴应纳税所得额") tree.heading("预扣税率", text="预扣税率") tree.heading("速算扣除数", text="速算扣除数") tree.insert("", 0, text="line1", values=("不超过36000元部分", "3%", "0")) tree.insert("", 1, text="line2", values=( "超过36000元至144000元的部分", "10%", "2520")) tree.insert("", 2, text="line3", values=( "超过144000元至300000元的部分", "20%", "16920")) tree.insert("", 3, text="line4", values=( "超过300000元至420000元的部分", "25%", "31920")) tree.insert("", 4, text="line5", values=( "超过420000元至660000元的部分", "30%", "52920")) tree.insert("", 5, text="line6", values=( "超过660000元至960000元的部分", "35%", "85920")) tree.insert("", 6, text="line6", values=( "超过960000元的部分", "45%", "181920")) tree.grid(row=7,columnspan=4 ) #root.mainloop()