tkinter计算个人所得税
时间: 2024-05-31 21:06:17 浏览: 34
Tkinter 是 Python 中的一个 GUI 库,可以用来创建窗口和各种用户界面。计算个人所得税是一个比较常见的应用场景,可以通过在 Tkinter 窗口中输入个人收入、专项扣除等信息,然后进行税前计算和税后计算,并将结果显示在窗口中。
以下是一个简单的 Tkinter 计算个人所得税的代码示例:
```
import tkinter as tk
def calculate_tax():
income = float(income_entry.get())
special_deduction = float(special_deduction_entry.get())
taxable_income = income - special_deduction - 5000
if taxable_income <= 0:
tax = 0
elif taxable_income <= 3000:
tax = taxable_income * 0.03
elif taxable_income <= 12000:
tax = taxable_income * 0.1 - 210
elif taxable_income <= 25000:
tax = taxable_income * 0.2 - 1410
elif taxable_income <= 35000:
tax = taxable_income * 0.25 - 2660
elif taxable_income <= 55000:
tax = taxable_income * 0.3 - 4410
elif taxable_income <= 80000:
tax = taxable_income * 0.35 - 7160
else:
tax = taxable_income * 0.45 - 15160
tax_before_label.config(text="税前收入:%.2f 元" % income)
special_deduction_label.config(text="专项扣除:%.2f 元" % special_deduction)
taxable_income_label.config(text="应纳税所得额:%.2f 元" % taxable_income)
tax_label.config(text="个人所得税:%.2f 元" % tax)
# 创建窗口
window = tk.Tk()
window.title("个人所得税计算器")
# 创建输入框和标签
income_label = tk.Label(window, text="税前收入:")
income_label.grid(row=0, column=0, padx=10, pady=10)
income_entry = tk.Entry(window)
income_entry.grid(row=0, column=1, padx=10, pady=10)
special_deduction_label = tk.Label(window, text="专项扣除:")
special_deduction_label.grid(row=1, column=0, padx=10, pady=10)
special_deduction_entry = tk.Entry(window)
special_deduction_entry.grid(row=1, column=1, padx=10, pady=10)
# 创建按钮
calculate_button = tk.Button(window, text="计算", command=calculate_tax)
calculate_button.grid(row=2, column=0, padx=10, pady=10)
# 创建结果标签
tax_before_label = tk.Label(window, text="")
tax_before_label.grid(row=3, column=0, padx=10, pady=10)
special_deduction_label = tk.Label(window, text="")
special_deduction_label.grid(row=4, column=0, padx=10, pady=10)
taxable_income_label = tk.Label(window, text="")
taxable_income_label.grid(row=5, column=0, padx=10, pady=10)
tax_label = tk.Label(window, text="")
tax_label.grid(row=6, column=0, padx=10, pady=10)
# 启动窗口
window.mainloop()
```
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)