浔川计算机v1.1——浔川python科技社

浔川计算机v1.1


import tkinter
import math
import tkinter.messagebox


class Calculator(object):
    # 界面布局方法
    def __init__(self):
        # 创建主界面,并且保存到成员属性中
        self.root = tkinter.Tk()
        self.root.minsize(280, 450)
        self.root.maxsize(280, 470)
        self.root.title('浔川计算器')
        # 设置显式面板的变量
        self.result = tkinter.StringVar()
        self.result.set(0)
        # 设置一个全局变量  运算数字和f符号的列表
        self.lists = []
        # 添加一个用于判断是否按下运算符号的标志
        self.ispresssign = False
        # 界面布局
        self.menus()
        self.layout()
        self.root.mainloop()
    # 计算器菜单界面摆放

    def menus(self):
        # 添加菜单
        # 创建总菜单
        allmenu = tkinter.Menu(self.root)
        # 添加子菜单
        filemenu = tkinter.Menu(allmenu, tearoff=0)
        # 添加选项卡
        filemenu.add_command(
            label='标准型(T)            Alt+1', command=self.myfunc)
        filemenu.add_command(
            label='科学型(S)            Alt+2', command=self.myfunc)
        filemenu.add_command(
            label='程序员(P)            Alt+3', command=self.myfunc)
        filemenu.add_command(label='统计信息(A)        Alt+4', command=self.myfunc)
        # 添加分割线
        filemenu.add_separator()
        # 添加选项卡
        filemenu.add_command(label='历史记录(Y)      Ctrl+H', command=self.myfunc)
        filemenu.add_command(label='数字分组(I)', command=self.myfunc)
        # 添加分割线
        filemenu.add_separator()
        # 添加选项卡
        filemenu.add_command(
            label='基本(B)             Ctrl+F4', command=self.myfunc)
        filemenu.add_command(label='单位转换(U)      Ctrl+U', command=self.myfunc)
        filemenu.add_command(label='日期计算(D)      Ctrl+E', command=self.myfunc)
        menu1 = tkinter.Menu(filemenu, tearoff=0)
        menu1.add_command(label='抵押(M)', command=self.myfunc)
        menu1.add_command(label='汽车租赁(V)', command=self.myfunc)
        menu1.add_command(label='油耗(mpg)(F)', command=self.myfunc)
        menu1.add_command(label='油耗(l/100km)(U)', command=self.myfunc)
        filemenu.add_cascade(label='工作表(W)', menu=menu1)
        allmenu.add_cascade(label='查看(V)', menu=filemenu)
        # 添加子菜单2
        editmenu = tkinter.Menu(allmenu, tearoff=0)
        # 添加选项卡
        editmenu.add_command(label='复制(C)         Ctrl+C', command=self.myfunc)
        editmenu.add_command(label='粘贴(V)         Ctrl+V', command=self.myfunc)
        # 添加分割线
        editmenu.add_separator()
        # 添加选项卡
        menu2 = tkinter.Menu(filemenu, tearoff=0)
        menu2.add_command(label='复制历史记录(I)', command=self.myfunc)
        menu2.add_command(
            label='编辑(E)                      F2', command=self.myfunc)
        menu2.add_command(label='取消编辑(N)            Esc', command=self.myfunc)
        menu2.add_command(label='清除(L)    Ctrl+Shift+D', command=self.myfunc)
        editmenu.add_cascade(label='历史记录(H)', menu=menu2)
        allmenu.add_cascade(label='编辑(E)', menu=editmenu)
        # 添加子菜单3
        helpmenu = tkinter.Menu(allmenu, tearoff=0)
        # 添加选项卡
        helpmenu.add_command(label='查看帮助(V)       F1', command=self.myfunc)
        # 添加分割线
        helpmenu.add_separator()
        # 添加选项卡
        helpmenu.add_command(label='关于计算器(A)', command=self.myfunc)
        allmenu.add_cascade(label='帮助(H)', menu=helpmenu)

        self.root.config(menu=allmenu)

    # 计算器主界面摆放

    def layout(self):
        # 显示屏
        result = tkinter.StringVar()
        result.set(0)
        show_label = tkinter.Label(self.root, bd=3, bg='white', font=(
            '宋体', 30), anchor='e', textvariable=self.result)
        show_label.place(x=5, y=20, width=270, height=70)
        # 功能按钮MC
        button_mc = tkinter.Button(self.root, text='MC', command=self.wait)
        button_mc.place(x=5, y=95, width=50, height=50)
        # 功能按钮MR
        button_mr = tkinter.Button(self.root, text='MR', command=self.wait)
        button_mr.place(x=60, y=95, width=50, height=50)
        # 功能按钮MS
        button_ms = tkinter.Button(self.root, text='MS', command=self.wait)
        button_ms.place(x=115, y=95, width=50, height=50)
        # 功能按钮M+
        button_mjia = tkinter.Button(self.root, text='M+', command=self.wait)
        button_mjia.place(x=170, y=95, width=50, height=50)
        # 功能按钮M-
        button_mjian = tkinter.Button(self.root, text='M-', command=self.wait)
        button_mjian.place(x=225, y=95, width=50, height=50)
        # 功能按钮←
        button_zuo = tkinter.Button(self.root, text='←', command=self.dele_one)
        button_zuo.place(x=5, y=150, width=50, height=50)
        # 功能按钮CE
        button_ce = tkinter.Button(
            self.root, text='CE', command=lambda: self.result.set(0))
        button_ce.place(x=60, y=150, width=50, height=50)
        # 功能按钮C
        button_c = tkinter.Button(self.root, text='C', command=self.sweeppress)
        button_c.place(x=115, y=150, width=50, height=50)
        # 功能按钮±
        button_zf = tkinter.Button(self.root, text='±', command=self.zf)
        button_zf.place(x=170, y=150, width=50, height=50)
        # 功能按钮√
        button_kpf = tkinter.Button(self.root, text='√', command=self.kpf)
        button_kpf.place(x=225, y=150, width=50, height=50)
        # 数字按钮7
        button_7 = tkinter.Button(
            self.root, text='7', command=lambda: self.pressnum('7'))
        button_7.place(x=5, y=205, width=50, height=50)
        # 数字按钮8
        button_8 = tkinter.Button(
            self.root, text='8', command=lambda: self.pressnum('8'))
        button_8.place(x=60, y=205, width=50, height=50)
        # 数字按钮9
        button_9 = tkinter.Button(
            self.root, text='9', command=lambda: self.pressnum('9'))
        button_9.place(x=115, y=205, width=50, height=50)
        # 功能按钮/
        button_division = tkinter.Button(
            self.root, text='/', command=lambda: self.presscalculate('/'))
        button_division.place(x=170, y=205, width=50, height=50)
        # 功能按钮%
        button_remainder = tkinter.Button(
            self.root, text='//', command=lambda: self.presscalculate('//'))
        button_remainder.place(x=225, y=205, width=50, height=50)
        # 数字按钮4
        button_4 = tkinter.Button(
            self.root, text='4', command=lambda: self.pressnum('4'))
        button_4.place(x=5, y=260, width=50, height=50)
        # 数字按钮5
        button_5 = tkinter.Button(
            self.root, text='5', command=lambda: self.pressnum('5'))
        button_5.place(x=60, y=260, width=50, height=50)
        # 数字按钮6
        button_6 = tkinter.Button(
            self.root, text='6', command=lambda: self.pressnum('6'))
        button_6.place(x=115, y=260, width=50, height=50)
        # 功能按钮*
        button_multiplication = tkinter.Button(
            self.root, text='*', command=lambda: self.presscalculate('*'))
        button_multiplication.place(x=170, y=260, width=50, height=50)
        # 功能按钮1/x
        button_reciprocal = tkinter.Button(
            self.root, text='1/x', command=self.ds)
        button_reciprocal.place(x=225, y=260, width=50, height=50)
        # 数字按钮1
        button_1 = tkinter.Button(
            self.root, text='1', command=lambda: self.pressnum('1'))
        button_1.place(x=5, y=315, width=50, height=50)
        # 数字按钮2
        button_2 = tkinter.Button(
            self.root, text='2', command=lambda: self.pressnum('2'))
        button_2.place(x=60, y=315, width=50, height=50)
        # 数字按钮3
        button_3 = tkinter.Button(
            self.root, text='3', command=lambda: self.pressnum('3'))
        button_3.place(x=115, y=315, width=50, height=50)
        # 功能按钮-
        button_subtraction = tkinter.Button(
            self.root, text='-', command=lambda: self.presscalculate('-'))
        button_subtraction.place(x=170, y=315, width=50, height=50)
        # 功能按钮=
        button_equal = tkinter.Button(
            self.root, text='=', command=lambda: self.pressequal())
        button_equal.place(x=225, y=315, width=50, height=105)
        # 数字按钮0
        button_0 = tkinter.Button(
            self.root, text='0', command=lambda: self.pressnum('0'))
        button_0.place(x=5, y=370, width=105, height=50)
        # 功能按钮.
        button_point = tkinter.Button(
            self.root, text='.', command=lambda: self.pressnum('.'))
        button_point.place(x=115, y=370, width=50, height=50)
        # 功能按钮+
        button_plus = tkinter.Button(
            self.root, text='+', command=lambda: self.presscalculate('+'))
        button_plus.place(x=170, y=370, width=50, height=50)
    # 计算器菜单功能
    def myfunc(self):
        tkinter.messagebox.showinfo('', '更新中.')
    # 数字方法
    def pressnum(self, num):
        # 全局化变量
        # 判断是否按下了运算符号
        if self.ispresssign == False:
            pass
        else:
            self.result.set(0)
            # 重置运算符号的状态
            self.ispresssign = False
        if num == '.':
            num = '0.'
        # 获取面板中的原有数字
        oldnum = self.result.get()
        # 判断界面数字是否为0
        if oldnum == '0':
            self.result.set(num)
        else:
            # 连接上新按下的数字
            newnum = oldnum + num

            # 将按下的数字写到面板中
            self.result.set(newnum)

    # 运算函数
    def presscalculate(self, sign):
        # 保存已经按下的数字和运算符号
        # 获取界面数字
        num = self.result.get()
        self.lists.append(num)
        # 保存按下的操作符号
        self.lists.append(sign)
        # 设置运算符号为按下状态
        self.ispresssign = True

    # 获取运算结果
    def pressequal(self):
        # 获取所有的列表中的内容(之前的数字和操作)
        # 获取当前界面上的数字
        curnum = self.result.get()
        # 将当前界面的数字存入列表
        self.lists.append(curnum)
        # 将列表转化为字符串
        calculatestr = ''.join(self.lists)
        # 使用eval执行字符串中的运算即可
        endnum = eval(calculatestr)
        # 将运算结果显示在界面中
        self.result.set(str(endnum)[:10])
        if self.lists != 0:
            self.ispresssign = True
        # 清空运算列表
        self.lists.clear()

    # 暂未开发说明
    def wait(self):
        tkinter.messagebox.showinfo('', '更新中......')
    # ←按键功能

    def dele_one(self):
        if self.result.get() == '' or self.result.get() == '0':
            self.result.set('0')
            return
        else:
            num = len(self.result.get())
            if num > 1:
                strnum = self.result.get()
                strnum = strnum[0:num - 1]
                self.result.set(strnum)
            else:
                self.result.set('0')
    # ±按键功能

    def zf(self):
        strnum = self.result.get()
        if strnum[0] == '-':
            self.result.set(strnum[1:])
        elif strnum[0] != '-' and strnum != '0':
            self.result.set('-' + strnum)
    # 1/x按键功能

    def ds(self):
        dsnum = 1 / int(self.result.get())
        self.result.set(str(dsnum)[:10])
        if self.lists != 0:
            self.ispresssign = True
        # 清空运算列表
        self.lists.clear()

    # C按键功能

    def sweeppress(self):
        self.lists.clear()
        self.result.set(0)
    # √按键功能

    def kpf(self):
        strnum = float(self.result.get())
        endnum = math.sqrt(strnum)
        if str(endnum)[-1] == '0':
            self.result.set(str(endnum)[:-2])
        else:
            self.result.set(str(endnum)[:10])
        if self.lists != 0:
            self.ispresssign = True
        # 清空运算列表
        self.lists.clear()


# 实例化对象
my_calculator = Calculator()

运行结果:


 本代码由浔川python社、浔川python科技社联合创作

 浔川计算机v2.1 即将上线!(上线时间:7月2日)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/710336.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

LabVIEW 32位与64位版本比较分析:性能与兼容性详解

LabVIEW的32位和64位版本在功能、性能、兼容性和应用场景等方面存在差异。本文从系统要求、内存管理、性能、兼容性、驱动支持和开发维护等多个角度进行详细分析,帮助用户选择合适的版本。 一、系统要求 操作系统支持: 32位LabVIEW:可以在32位…

vue+elementUI实现在表格中添加输入框并校验的功能

背景: vue2elmui 需求: 需要在一个table中添加若干个输入框,并且在提交时需要添加校验 思路: 当需要校验的时候可以考虑添加form表单来触发校验,因此需要在table外面套一层form表单,表单的属性就是ref…

ComfyUI 宝藏插件之辅助工具

今天我们就来分享下这个 ComfyUI 辅助脚本工具的功能。 插件安装,小伙伴们直接在管理器里搜索「ComfyUI-Custom-Scripts」,点击安装就可以了,这里再告诉小伙伴们一个小技巧,点击名称可以跳转到插件所在的官网哦。 没有安装管理器…

Tdengine的时序数据库简介、单机部署、操作语句及java应用

Tdengine的时序数据库简介、单机部署、操作语句及java应用 本文介绍了Tdengine的功能特点、应用场景、超级表和子表等概念,讲述了Tdengine2.6.0.34的单机部署,并介绍了taos数据库的常见使用方法及特色窗口查询方法,最后介绍了在java中的应用。…

AI助力密码安全:利用机器学习提升密码安全性

信息安全已经成为了当今数字世界的一个核心问题,随着互联网技术使用场景的不断增加,创建和管理安全的密码已经成为了保证在线账户安全的关键要求。本文将研究和探讨如何利用人工智能(AI)和机器学习技术来提升密码的安全性。 学习目…

xgo 原理探索

Go 单测 mock 方案 Mock 方法原理依赖优点缺点接口 Mock为依赖项定义接口,并提供接口的 Mock 实现。需要定义接口和 Mock 实现。灵活,遵循 Go 的类型系统;易于替换实现。需要更多的样板代码来定义接口和 Mock 实现。Monkey Patching&#xf…

深度学习网络结构之---Inception

目录 一、Inception名称的由来 二、Inception结构 三、Inception v2 四、Inception v3 1、深度网络的通用设计原则 2.卷积分解(Factorizing Convolutions) 3.对称卷积分解 3.非对称卷积分解 五、Inception v4 一、Inception名称的由来 Inception网…

推荐一款好用的读论文软件操作方法

步骤: 1. 使用一译 —— 文档和论文翻译、对照阅读、讨论和社区 2.上传自己想要翻译的论文即可。 示例 Planing论文双语翻译 1.1 Parting with Misconceptions about Learning-based Vehicle Motion Planning 中英文对照阅读 1.2 Rethinking Imitation-based Pl…

3.多层感知机

目录 1.感知机训练感知机XOR问题(Minsky&Papert 1969) AI的第一个寒冬总结 2.多层感知机(MLP)学习XOR单隐藏层(全连接层)激活函数:Sigmoid激活函数:Tanh激活函数:ReLu 最常用的 因为计算速度…

AMSR-MODIS 边界层水汽 L3 每日 1 度 x 1 度 V1、V2 版本数据集

AMSR-MODIS Boundary Layer Water Vapor L3 Daily 1 degree x 1 degree V1 (AMDBLWV) at GES DISC AMSR-MODIS Boundary Layer Water Vapor L3 Daily 1 degree x 1 degree V2 (AMDBLWV) at GES DISC 简介 该数据集可估算均匀云层下的海洋边界层水汽。AMSR-E 和 AMSR-2 的微波…

使用libcurl实现简单的HTTP访问

代码; #include <stdio.h> #include <stdlib.h> #include <curl/curl.h> // 包含libcurl库 FILE *fp; // 定义一个文件标识符 size_t write_data(void *ptr,size_t size,size_t nmemb,void *stream) { // 定义回调函数&#xff0c;用于将…

MGRS坐标

一 概述 MGRS坐标系统&#xff0c;即军事格网参考系统&#xff0c;是北约(NATO)军事组织使用的标准坐标系统。它基于UTM&#xff08;通用横向墨卡托&#xff09;系统&#xff0c;并将每个UTM区域进一步划分为100km100km的小方块。这些方块通过两个相连的字母标识&#xff0c;其…

华为云开发者社区活动-基于MindNLP的ChatGLM-6B聊天机器人体验

MindNLP ChatGLM-6B StreamChat 本案例基于MindNLP和ChatGLM-6B实现一个聊天应用。支持流式回复。 本活动通过配置环境&#xff0c;模型接入&#xff0c;以及gradio前端界面搭建&#xff0c;实现了聊天机器人的功能。 以下是一些体验记录&#xff1a; 有兴趣的可以通过以下链…

详细解析找不到msvcp120.dll文件的原因及解决方法

在计算机使用过程中&#xff0c;我们经常会遇到一些错误提示&#xff0c;其中之一就是“找不到msvcp120.dll”。这个错误提示通常出现在运行某些程序或游戏时&#xff0c;给使用者带来了困扰。那么&#xff0c;究竟是什么原因导致了这个问题的出现&#xff1f;又该如何解决呢&a…

【每日刷题】Day64

【每日刷题】Day64 &#x1f955;个人主页&#xff1a;开敲&#x1f349; &#x1f525;所属专栏&#xff1a;每日刷题&#x1f34d; &#x1f33c;文章目录&#x1f33c; 1. LCP 67. 装饰树 - 力扣&#xff08;LeetCode&#xff09; 3. 1315. 祖父节点值为偶数的节点和 - 力…

PyQT5 中关于 QCheckBox 的勾选状态的一点小细节

一、QCheckBox 是 PyQt5 中的一个用于创建复选框的控件&#xff0c;以下是其一些常见方法和属性&#xff1a; setChecked: 设置复选框的选中状态。isChecked: 检查复选框是否被选中。text: 设置或获取复选框的文本。state: 获取复选框的状态&#xff08;无、选中、不可用等&am…

公差基础-配合(互换性和测量基础)-2

过盈配合&#xff1a; 配合的种类&#xff1a; 三种&#xff1a;间隙&#xff0c;过渡&#xff0c;过盈配 间隙配合&#xff1a; 过盈配合&#xff1a; 过渡配合&#xff1a; 间隙量&#xff1a;最大间隙减去最小间隙&#xff1b; 配合的公差怎么算&#xff1a; 练习&#xff…

Git 代码管理规范 !

分支命名 master 分支 master 为主分支&#xff0c;也是用于部署生产环境的分支&#xff0c;需要确保master分支稳定性。master 分支一般由 release 以及 hotfix 分支合并&#xff0c;任何时间都不能直接修改代码。 develop 分支 develop 为开发环境分支&#xff0c;始终保持最…

如何在 Go 应用程序中使用检索增强生成(RAG)

本文将帮助大家实现 RAG &#xff08;使用 LangChain 和 PostgreSQL &#xff09;以提高 LLM 输出的准确性和相关性。 得益于强大的机器学习模型&#xff08;特别是由托管平台/服务通过 API 调用公开的大型语言模型&#xff0c;如 Claude 的 LLama 2等&#xff09;&#xff0c…

创邻科技张晨:期待解锁图技术在供应链中的关联力

近日&#xff0c;创邻科技创始人兼CEO张晨博士受浙江省首席信息官协会邀请&#xff0c;参加数字化转型与企业出海研讨会。 此次研讨会旨在深入探讨数字经济时代下&#xff0c;企业如何有效应对成本提升与环境变化所带来的挑战&#xff0c;通过数字化转型实现提效增益&#xff…