输入存款金额,7日年化收益率,输出每日利息
完整源码如下:
import tkinter as tk
from tkinter import messageboxdef calculate_interest():deposit = float(entry_deposit.get())interest_rate = float(entry_interest_rate.get())daily_interest_rate = interest_rate / 365 # 计算每日利率daily_interest = round(deposit * daily_interest_rate, 2) # 计算每日收益并保留两位小数result_label.config(text=f"每天的收益为:{daily_interest}")# 创建窗口
window = tk.Tk()
window.title("存款利息计算器")
window.geometry("400x200") # 设置窗口大小# 创建标签和输入框
label_deposit = tk.Label(window, text="存款金额:")
label_deposit.pack()
entry_deposit = tk.Entry(window)
entry_deposit.pack()label_interest_rate = tk.Label(window, text="7日年化收益率:")
label_interest_rate.pack()
entry_interest_rate = tk.Entry(window)
entry_interest_rate.pack()# 创建按钮
button_calculate = tk.Button(window, text="计算", command=calculate_interest)
button_calculate.pack()# 创建结果标签
result_label = tk.Label(window, text="每天的收益为:")
result_label.pack()# 运行窗口
window.mainloop()
运行结果如下:
10万和1000万的情况