python我的所得税计算器_Python写了个小工具,个人所得税计算器 - Python - 批处理之家 批处理_BAT脚本_PowerShell_VBS_CMD_DOS_Perl_Python ...

这篇博客介绍了如何使用Python创建一个简单的个人所得税计算器应用。通过Tkinter库实现GUI界面,用户输入税前工资和扣除的保险金额,程序将自动计算并显示应纳税额、应缴个税和税后工资。
摘要由CSDN通过智能技术生成

import tkinter as tk

import tkinter.ttk as ttk

class TaxCalc(object):

taxPoint = 5000

def __init__(self):

self.top = tk.Tk()

self.top.title("个人所得税计算器")

sw,sh = self.top.winfo_screenwidth(),self.top.winfo_screenheight()

ww,wh = 245,280

self.top.geometry("{}x{}+{}+{}".format(ww,wh,(sw-ww)//2,(sh-wh)//2))

self.top.resizable(0,0)

self.createWdiget()

self.top.wm_attributes('-topmost',1)  #主窗口置顶

self.top.mainloop()

def createWdiget(self):

self.beforeTaxLable = tk.Label(self.top,text="税前工资:")

self.beforeTaxLable.grid(row=0,column=0)

self.beforeTaxEntry = tk.Entry(self.top)

self.beforeTaxEntry.grid(row=0,column=1,pady=10,padx=10)

self.insuranceLable= tk.Label(self.top,text="扣除的保险:")

self.insuranceLable.grid(row=1,column=0)

self.insuranceEntry = tk.Entry(self.top)

self.insuranceEntry.grid(row=1,column=1,pady=10)

#绑定事件,离开焦点或按回车就试着调用计算的函数

self.insuranceEntry.bind("",self.calcTax)

self.insuranceEntry.bind("",self.calcTax)

self.sep = ttk.Separator(self.top, orient=tk.HORIZONTAL)

self.sep.grid(row=2,column=0,columnspan=2,sticky="ew")

self.taxAmoutLable = tk.Label(self.top,text="应纳税额:")

self.taxAmoutLable.grid(row=3,column=0)

self.taxAmoutEntry = tk.Entry(self.top)

self.taxAmoutEntry.grid(row=3,column=1,pady=10)

self.taxLable = tk.Label(self.top,text="应缴个税:")

self.taxLable.grid(row=4,column=0)

self.taxEntry = tk.Entry(self.top)

self.taxEntry.grid(row=4,column=1,pady=10)

self.afterTaxLable = tk.Label(self.top,text="税后工资:")

self.afterTaxLable.grid(row=5,column=0)

self.afterTaxEntry = tk.Entry(self.top)

self.afterTaxEntry.grid(row=5,column=1,pady=10)

self.calcBtn = ttk.Button(self.top,text="计算")

self.calcBtn.grid(row=6,column=1,pady=10)

self.calcBtn.bind("",self.calcTax)   #不能直接用Button的command参数绑定,commmand默认不传event参数

def calcTax(self,event):     #做为事件的回调函数须要有event参数

try:

beforeTax = float(self.beforeTaxEntry.get())

insurance = float(self.insuranceEntry.get())

except ValueError as e:   #空或非数字转成浮点时都会捕获,但不做响应

pass

else:

taxAmout = beforeTax - insurance - TaxCalc.taxPoint if (beforeTax - insurance) > TaxCalc.taxPoint else 0

if taxAmout < 3000:

tax = taxAmout*0.03

elif taxAmout < 12000:

tax = taxAmout*0.1-210

elif taxAmout < 25000:

tax = taxAmout*0.2-1410

elif taxAmout < 35000:

tax = taxAmout*0.25-2660

elif taxAmout < 55000:

tax = taxAmout*0.3-4410

elif taxAmout < 80000:

tax = taxAmout*0.35-7160

else:

tax = taxAmout*0.45-15160

afterTax = beforeTax - insurance -tax

taxAmout = "{0:.2f}".format(taxAmout)

tax = "{0:.2f}".format(tax)

afterTax = "{0:.2f}".format(afterTax)

self.taxAmoutEntry.delete(0,tk.END)

self.taxAmoutEntry.insert(0, taxAmout)

self.taxEntry.delete(0,tk.END)

self.taxEntry.insert(0,tax)

self.afterTaxEntry.delete(0,tk.END)

self.afterTaxEntry.insert(0, afterTax)

if __name__ == '__main__':

s = TaxCalc()

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值