最近在学习python,用tkinter编写了一个银行理财计算器。
仅供参考使用。
仅供参考使用。
仅供参考使用。
以下是源码:(初学python,有不对之处请大家指教。)
import tkinter as tk
from tkinter.constants import END, FALSE, GROOVE, LEFT, RIDGE, RIGHT
import tkinter.messagebox
def isscalar(str):
try:
float(str)
except ValueError:
return False
else:
return True
def is_int(str):
try:
int(str)
except ValueError:
return False
else:
return True
def cal():
if day.get() == '' or percent.get() == '' or investment.get() == '':
tkinter.messagebox.showinfo('提示', '期限、预期年化收益率、投资金额,不能为空。')
elif isscalar(day.get()) == False or isscalar(percent.get()) == False or isscalar(investment.get()) == False:
tkinter.messagebox.showerror('提示', '请在"期限、预期年化收益率、投资金额"内输入数字。')
elif is_int(day.get()) == False or is_int(investment.get()) == False:
tkinter.messagebox.showinfo('提示', '"期限"或者"投资金额":请输入整数。')
else:
shouyi = int(investment.get())*float(percent.get()) / \
100*int(day.get())/360*10000
proceeds.config(text=round(shouyi, 2))
def cls_all():
day.delete(0,END)
percent.delete(0,END)
investment.delete(0,END)
proceeds.config(text='00.00')
day.focus_set()
window = tk.Tk()
window.title('银行理财计算器')
window.geometry('570x500')
window.resizable(width=False, height=False)
title = tk.Label(window, text='银行理财计算器', width=20, height=2, font=('微软雅黑', 30))
# title.place(x=100,y=100)
title.pack()
lb1 = tk.Label(window, text='期限', font=('微软雅黑', 20), justify=LEFT)
lb1.place(x=185, y=120)
day = tk.Entry(window, font=('微软雅黑', 20), width=10)
day.place(x=270, y=120)
lb2 = tk.Label(window, text='天', font=('微软雅黑', 20))
lb2.place(x=450, y=120)
lb3 = tk.Label(window, text='预期年化收益率', font=('微软雅黑', 20), justify=LEFT)
lb3.place(x=50, y=170)
percent = tk.Entry(window, font=('微软雅黑', 20), width=10)
percent.place(x=270, y=170)
lb4 = tk.Label(window, text='%', font=('微软雅黑', 20))
lb4.place(x=450, y=170)
lb5 = tk.Label(window, text='投资金额', font=('微软雅黑', 20), justify=LEFT)
lb5.place(x=131, y=220)
investment = tk.Entry(window, font=('微软雅黑', 20), width=10)
investment.place(x=270, y=220)
lb6 = tk.Label(window, text='万元', font=('微软雅黑', 20))
lb6.place(x=450, y=220)
lb7 = tk.Label(window, text='预期收益', font=('微软雅黑', 20), justify=LEFT)
lb7.place(x=131, y=270)
proceeds = tk.Label(window, text='00.00', font=(
'微软雅黑', 20), justify=LEFT, fg='red')
proceeds.place(x=270, y=270)
lb8 = tk.Label(window, text='元', font=('微软雅黑', 20))
lb8.place(x=450, y=270)
btn1 = tk.Button(window, text='计算', font=('微软雅黑', 20), width=10, command=cal)
btn1.place(x=100, y=340)
btn2 = tk.Button(window, text='重置', font=(
'微软雅黑', 20), width=10, command=cls_all)
btn2.place(x=300, y=340)
lb9 = tk.Label(
window, text='Powered by Python 3.9.5 @ china-ray', font=('微软雅黑', 10))
lb9.place(x=320, y=470)
day.focus_set()
window.mainloop()
第一次发帖,如违规请删帖。
链接:https://pan.baidu.com/s/1vuQixz7F487-CKN_czCz9g
提取码:gicd
复制这段内容后打开百度网盘手机App,操作更方便哦
|