包含登录界面的计算器软件

一、实验背景

        实验目的:

                ① 掌握软件开发的基本流程。

                ② 掌握常用的软件开发方式和工具。

        实验内容:

                ① 设计并实现一个包含登录界面的计算器软件。

                ② 软件需具备历史记录功能,能保存用户计算记录。

二、实验要求

1.  完成软件的UI设计、使用Visio设计软件中所涉及的所有流程图。

2.  选择合适的集成开发环境和工具完成计算器软件的开发

3.  将开发好软件进行测试并截图

4.  将本次实验过程写成实验报告提交在本次作业的链接中
        
 5.  关键代码部分以代码块格式粘贴在实验报告正文中

6.  软件架构以及开发技术不限

三、实验设计与实现 

UI设计

        登录界面设计

                        使用了HTMl语言做出了一个网页版的登陆界面

        界面如下

                主界面设计


                计算界面设计

                流程图设计

                登录流程图

                计算流程图

                历史记录查询流程图

软件开发

        选择开发语言和框架。

                开发语言使用了HTML语言和python,实现登录和注册功能并且同时实现计算功能。

测试与截图
        
        对软件的各个功能进行测试。

                截取软件运行成功的界面图。

四、实验结果与分析

        功能测试

                登录功能测试。

                计算功能测试。

                历史记录功能测试。

        性能分析

                软件运行效率分析

                内存占用分析

 五、实验总结

         总结实验中学到的知识点

        分析实验过程中的问题和改进方向

六、代码块展示

import tkinter as tk
from tkinter import simpledialog
import json
import math


# 登录界面
def login():
    username = simpledialog.askstring("登录", "请输入用户名:")
    password = simpledialog.askstring("登录", "请输入密码:")

    if username == "admin" and password == "123456":
        return True
    else:
        return False


# 保存历史记录
def save_history(history):
    with open("/mnt/data/calculator_history.json", "w", encoding="utf-8") as f:
        json.dump(history, f)


# 读取历史记录
def load_history():
    try:
        with open("/mnt/data/calculator_history.json", "r", encoding="utf-8") as f:
            return json.load(f)
    except FileNotFoundError:
        return []


# 计算器功能
def calculator():
    # 登录
    if not login():
        return

    # 保存历史记录
    history = load_history()
    history.append({
        "expression": entry.get(),
        "result": result.get()
    })
    save_history(history)

    # 清空输入
    entry.delete(0, tk.END)
    result.delete(0, tk.END)

    # 计算表达式
    try:
        expression = entry.get()
        if expression.isalnum() or expression in ["+", "-", "*", "/", "^", "sin", "cos", "tan"]:
            result.set(eval(expression))
        else:
            result.set("错误:无效的表达式")

    except Exception as e:
        result.set("错误:计算出错")


# 构建 GUI
root = tk.Tk()
root.title("计算器软件")

frame = tk.Frame(root)
frame.pack(padx=10, pady=10)

entry = tk.Entry(frame, width=30)
entry.grid(row=0, column=0, columnspan=4)

result = tk.Entry(frame, width=20, state="readonly")
result.grid(row=1, column=0, columnspan=4)

button_0 = tk.Button(frame, text="0", command=lambda: entry.insert(tk.END, "0"))
button_0.grid(row=2, column=0)

button_1 = tk.Button(frame, text="1", command=lambda: entry.insert(tk.END, "1"))
button_1.grid(row=2, column=1)

button_2 = tk.Button(frame, text="2", command=lambda: entry.insert(tk.END, "2"))
button_2.grid(row=2, column=2)

button_3 = tk.Button(frame, text="3", command=lambda: entry.insert(tk.END, "3"))
button_3.grid(row=2, column=3)

button_4 = tk.Button(frame, text="4", command=lambda: entry.insert(tk.END, "4"))
button_4.grid(row=3, column=0)

button_5 = tk.Button(frame, text="5", command=lambda: entry.insert(tk.END, "5"))
button_5.grid(row=3, column=1)

button_6 = tk.Button(frame, text="6", command=lambda: entry.insert(tk.END, "6"))
button_6.grid(row=3, column=2)

button_7 = tk.Button(frame, text="7", command=lambda: entry.insert(tk.END, "7"))
button_7.grid(row=3, column=3)

button_8 = tk.Button(frame, text="8", command=lambda: entry.insert(tk.END, "8"))
button_8.grid(row=4, column=0)

button_9 = tk.Button(frame, text="9", command=lambda: entry.insert(tk.END, "9"))
button_9.grid(row=4, column=1)

button_dot = tk.Button(frame, text=".", command=lambda: entry.insert(tk.END, "."))
button_dot.grid(row=4, column=2)

button_equal = tk.Button(frame, text="=", command=calculator)
button_equal.grid(row=4, column=3)

button_plus = tk.Button(frame, text="+", command=lambda: entry.insert(tk.END, "+"))
button_plus.grid(row=5, column=0)

button_minus = tk.Button(frame, text="-", command=lambda: entry.insert(tk.END, "-"))
button_minus.grid(row=5, column=1)

button_multiply = tk.Button(frame, text="*", command=lambda: entry.insert(tk.END, "*"))
button_multiply.grid(row=5, column=2)

button_divide = tk.Button(frame, text="/", command=lambda: entry.insert(tk.END, "/"))
button_divide.grid(row=5, column=3)

button_power = tk.Button(frame, text="^", command=lambda: entry.insert(tk.END, "^"))
button_power.grid(row=6, column=1)

button_sin = tk.Button(frame, text="sin", command=lambda: entry.insert(tk.END, "sin"))
button_sin.grid(row=6, column=2)

button_cos = tk.Button(frame, text="cos", command=lambda: entry.insert(tk.END, "cos"))
button_cos.grid(row=6, column=3)

button_tan = tk.Button(frame, text="tan", command=lambda: entry.insert(tk.END, "tan"))
button_tan.grid(row=6, column=0)

button_clear = tk.Button(frame, text="C", command=lambda: entry.delete(0, tk.END))
button_clear.grid(row=7, column=1)

button_percent = tk.Button(frame, text="%", command=lambda: entry.insert(tk.END, "%"))
button_percent.grid(row=7, column=2)

button_pi = tk.Button(frame, text="π", command=lambda: entry.insert(tk.END, "π"))
button_pi.grid(row=7, column=3)

button_sqrt = tk.Button(frame, text="√", command=lambda: entry.insert(tk.END, "√"))
button_sqrt.grid(row=7, column=0)

root.mainloop()

  • 6
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值