简单计算器 -python

  • 初步界面
  • 初步一位运算

这几天才突然明白,很多屏幕原点坐标点原来在左上角…

from tkinter import *
from time import sleepx = t = y = 0
base = Tk()
base.title("计算器")
base.geometry("250x380")frame_top = Frame(width = 250, height = 80, bg = '#dddddd')
frame_top.pack()sv = StringVar()
sv.set("0.0")num1 = 0
num2 = 0
num1_1 = 999
num2_2 = 999
op = None
def show_num(num):global num1, num2, op, num1_1, num2_2, t, x, yif not op:if num == num1_1:sv.set(num1_1)else:num1 +=int(num)sv.set(num)num1_1 = numelse:if num == num2_2:sv.set(str(num1) + op + str(num))else:num2 += int(num)""" if t == True:x = num1 +  0.1* int(num)y = int(num)show_del(0)num1 = xprint(num1, num2)sv.set(str(num1))else: """sv.set(str(int(num1)) + op + str(num2))num2_2 = numdef show_op(opr):global num1, num2, op, tif opr in ['+', '-', '×', '÷', '%', '.']:op = oprsv.set(str(num1)+ op)if opr == '.':t = Trueelse:if op == '+':nums = num1 + num2if op == '-':nums = num1 - num2if op == '×':nums = num1 * num2if op == '÷':nums = num1 / num2if op == '%':nums = num1 % num2sv.set(nums)show_del(0)
def show_yx(num):sv.set(num)
def show_del(num):global num1, num2, op, num1_1, num2_2if num == 1:sv.set("0.0")num1 = 0num2 = 0num1_1 = 999num2_2 = 999op = None label_top = Label(frame_top, textvariable = sv, width = 200, height = 2, font = ('黑体', 20, "bold"), anchor = 'e', bg = '#cccccc', justify = LEFT)
label_top.pack(padx = 10, pady = 10)frame_bottom = Frame(width = 400, height = 350, bg = '#cccccc')button_m = Button(frame_bottom, text = "影", width = 7, height = 2, command = lambda:show_yx("嘤嘤嘤"))
button_m.grid(row = 0, column = 0)
button_n = Button(frame_bottom, text = "修", width = 7, height = 2, command = lambda:show_yx("羞羞羞"))
button_n.grid(row = 0, column = 1)
button_chu = Button(frame_bottom, text = "%", width = 7, height = 2, command = lambda:show_op("%"))
button_chu.grid(row = 0, column = 2)
button_c = Button(frame_bottom, text = "C", width = 7, height = 2, command = lambda:show_del(1))
button_c.grid(row = 0, column = 3)button_7 = Button(frame_bottom, text = "7", width = 7, height = 2, command = lambda:show_num("7"))
button_7.grid(row = 1, column = 0)
button_8 = Button(frame_bottom, text = "8", width = 7, height = 2, command = lambda:show_num("8"))
button_8.grid(row = 1, column = 1)
button_9 = Button(frame_bottom, text = "9", width = 7, height = 2, command = lambda:show_num("9"))
button_9.grid(row = 1, column = 2)
button_chu = Button(frame_bottom, text = "/", width = 7, height = 2, command = lambda:show_op("÷"))
button_chu.grid(row = 1, column = 3)button_4 = Button(frame_bottom, text = "4", width = 7, height = 2, command = lambda:show_num("4"))
button_4.grid(row = 2, column = 0)
button_5 = Button(frame_bottom, text = "5", width = 7, height = 2, command = lambda:show_num("5"))
button_5.grid(row = 2, column = 1)
button_6 = Button(frame_bottom, text = "6", width = 7, height = 2, command = lambda:show_num("6"))
button_6.grid(row = 2, column = 2)
button_cheng = Button(frame_bottom, text = "*", width = 7, height = 2, command = lambda:show_op("×"))
button_cheng.grid(row = 2, column = 3)button_1 = Button(frame_bottom, text = "1", width = 7, height = 2, command = lambda:show_num("1"))
button_1.grid(row = 3, column = 0)
button_2 = Button(frame_bottom, text = "2", width = 7, height = 2, command = lambda:show_num("2"))
button_2.grid(row = 3, column = 1)
button_3 = Button(frame_bottom, text = "3", width = 7, height = 2, command = lambda:show_num("3"))
button_3.grid(row = 3, column = 2)
button_jian = Button(frame_bottom, text = "-", width = 7, height = 2, command = lambda:show_op("-"))
button_jian.grid(row = 3, column = 3)button_0 = Button(frame_bottom, text = "0", width = 7, height = 2, command = lambda:show_num("0"))
button_0.grid(row = 4, column = 0)
button_dian = Button(frame_bottom, text = ".", width = 7, height = 2, command = lambda:show_op("."))
button_dian.grid(row = 4, column = 1)
button_dengyu = Button(frame_bottom, text = "=", width = 7, height = 2, command = lambda:show_op('='))
button_dengyu.grid(row = 4, column = 2)
button_jia = Button(frame_bottom, text = "+", width = 7, height = 2, command = lambda:show_op("+"))
button_jia.grid(row = 4, column = 3)frame_bottom.pack(padx = 10, pady = 10)

简单计算器 -python相关推荐

  1. Python基础项目实践之:面向对象方法模拟简单计算器

    Python课堂基础实践系列: Python基础项目实践之:学生信息管理系统 python基础项目实践之: 学生通讯录管理系统 Python基础项目实践之:面向对象方法模拟简单计算器 Python基础 ...

  2. 用Python解“两个数的简单计算器”题

    7-12 两个数的简单计算器 本题要求编写一个简单计算器程序,可根据输入的运算符,对2个整数进行加.减.乘.除或求余运算.题目保证输入和输出均不超过整型范围. 输入格式: 输入在一行中依次输入操作数1 ...

  3. python实现简单计算器功能键介绍_Python实现的简单计算器功能详解

    本文实例讲述了Python实现的简单计算器功能.分享给大家供大家参考,具体如下: 使用python编写一款简易的计算器 计算器效果图 首先搭建计算器的面板: 计算器面板结构 建造一个继承于wx.Fra ...

  4. python实现简单计算器_Python实现的简单计算器功能详解

    本文实例讲述了Python实现的简单计算器功能.分享给大家供大家参考,具体如下: 使用python编写一款简易的计算器 计算器效果图 首先搭建计算器的面板: 计算器面板结构 建造一个继承于wx.Fra ...

  5. 作业1开发一个简单的python计算器

    开发一个简单的python计算器 实现加减乘除及拓号优先级解析 用户输入 1 - 2 * ( (60-30 +(-40/5) * (9-2*5/3 + 7 /3*99/4*2998 +10 * 568 ...

  6. python数字计算器,Python 简单计算器实现

    Python 简单计算器实现 以下代码用于实现简单计算器实现,包括两个数基本的加减乘除运输: # Filename : test.py # author by : www.w3cschool.cn # ...

  7. 的python输入两个运算数及一个运算符_用Python解“两个数的简单计算器”题

    7-12 两个数的简单计算器 本题要求编写一个简单计算器程序,可根据输入的运算符,对2个整数进行加.减.乘.除或求余运算.题目保证输入和输出均不超过整型范围. 输入格式: 输入在一行中依次输入操作数1 ...

  8. python简单计算器综合实验报告_Python实现的简单计算器功能详解

    本文实例讲述了Python实现的简单计算器功能.分享给大家供大家参考,具体如下: 使用python编写一款简易的计算器 计算器效果图 首先搭建计算器的面板: 计算器面板结构 建造一个继承于wx.Fra ...

  9. python编程简易计算器_Python编程练习049:简单计算器实现

    以下代码用于实现简单计算器实现,包括两个数基本的加减乘除运算: 定义函数 def add(x, y): """相加""" return x ...

最新文章

  1. CVE-2012-0158栈溢出漏洞分析
  2. CLion 生成CMakeList文件和include文件不存在问题
  3. 第三次学JAVA再学不好就吃翔(part93)--LinkedHashMap
  4. 【LeetCode 剑指offer刷题】查找与排序题12:Top K Frequent Elements
  5. Linux-insmod/rmmod/lsmod驱动模块相关命令(10)
  6. python支持什么循环_Python的循环
  7. 从高斯消元到矩阵的三角分解(LU)
  8. 恋爱物语iapp源码导入就可以用
  9. IT 架构测试之基础架构运维测试简介
  10. html中button标签reset用法
  11. 基于方格网法的填挖方量计算(C++)
  12. Qt QLineEdit自带右键菜单的翻译
  13. 微软skype收购案
  14. pcr台服服务器连接中断,公主连结台服入坑 pcr台服入坑初始指南
  15. IE 获取 本地 Mac地址
  16. google earth中显示点云
  17. 18位身份证号码规则及js验证
  18. 手机关机收不到微信消息_为什么手机休眠的时候收不到微信 解决方法
  19. 技术总监/技术leader 职责与工作记录 第二天(包含技术部门规范示例)
  20. nginx域名访问的白名单配置梳理

热门文章

  1. jquery 筛选不到 checkbox, radio 表单元素
  2. career english
  3. 华为机试HJ2:计算某字母出现次数
  4. win7桌面取消显示计算机,教您win7系统关闭右下角显示桌面功能的解决办法
  5. 用计算机语言拜年,鸡年大吉!22种编程语言大拜年
  6. Android8.0 开机启动脚本,Android开机启动shell脚本(Android 8.0测试OK)
  7. qfiledialog的取消_QFileDialog类(老九学堂C++会员友情翻译,不喜勿喷)
  8. python安装方法_听说你安装Python包很慢,试试这个方法
  9. linux搭建博客Day1
  10. java 实现复制_在java中如何实现复制,粘贴,剪切