一鍵計算稅項支出

稅項支出是每一位有責任的納稅人的必要支出.

現在我們試一試用Python做出一個一鍵就知總數的程式.

python 复制代码
import tkinter as tk
from tkinter import messagebox

def calculate_total():
    try:
        # 讀取輸入框的值
        price = float(entry_price.get())
        tax = float(entry_tax.get())
        # 套用公式 Total = Price * Tax
        total = price * tax
        # 顯示結果
        messagebox.showinfo("計算結果", f"Total = {total}")
    except ValueError:
        messagebox.showerror("錯誤", "請輸入正確的數字!")

root = tk.Tk()
root.title("輸入資料計算 Total")

# Label 在第 0 行第 0 欄
tk.Label(root, text="價格 Price:").grid(row=0, column=0)
# Entry 在第 0 行第 1 欄
entry_price = tk.Entry(root)
entry_price.grid(row=0, column=1)

# Label 在第 1 行第 0 欄
tk.Label(root, text="稅率 Tax:").grid(row=1, column=0)
# Entry 在第 1 行第 1 欄
entry_tax = tk.Entry(root)
entry_tax.grid(row=1, column=1)

# 計算按鈕在第 2 行
tk.Button(root, text="計算 Total", command=calculate_total).grid(row=2, column=0, columnspan=2)

root.mainloop()在这里插入代码片

大家也可以試試其他的公式,用法也是大同小異,但如果要知運行結果,我想要拉到有圖像處理的軟體.

相关推荐
cup1140 分钟前
[技术复盘] Windows Python 打包实战:Nuitka 环境踩坑总结与 CI 自动化构建全指南
python·ai·环境变量·ci·nuitka·skill
aqi003 小时前
15天学会AI应用开发(七)有了大模型为什么还要引入RAG
人工智能·python·大模型·ai编程·ai应用
金銀銅鐵5 小时前
用 Python 实现 Take-Away 游戏
python·游戏
copyer_xyf5 小时前
Agent 流程编排
后端·python·agent
copyer_xyf6 小时前
Agent RAG
后端·python·agent
copyer_xyf6 小时前
【RAG】向量数据库:milvus
后端·python·agent
copyer_xyf6 小时前
Agent 记忆管理
后端·python·agent
星云穿梭21 小时前
用Python写一个带图形界面的学生管理系统——完整教程
python
金銀銅鐵21 小时前
用 Pygame 实现 15 puzzle
python·数学·游戏