你回来了?
我们一直在隔壁!

【Python源码】银行理财计算器

需要用到tkinter

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()
赞(0)
版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权
文章名称:《【Python源码】银行理财计算器》
文章链接:https://www.gebizhan.com/1196.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。

隔壁评论 抢沙发

快来看啊,隔壁站!

我们就是隔壁站的老王

隔壁邮箱隔壁TG

登录

找回密码

注册