随便写写

import sys
import calc
from PyQt4 import QtCore, QtGui class MyWidget(QtGui.QWidget):
num1 = ""
num2 = ""
point1 = 0
point2 = 0
opera = 0
opera_add = 0
opera_minus = 0
opera_mul = 0
opera_div = 0 def __init__(self):
super(MyWidget, self).__init__()
self.the_ui = calc.Ui_widget()
self.the_ui.setupUi(self)
self.connect(self.the_ui.btn_one, QtCore.SIGNAL('clicked()'), self, QtCore.SLOT('click_one()'))
self.connect(self.the_ui.btn_two, QtCore.SIGNAL('clicked()'), self, QtCore.SLOT('click_two()'))
self.connect(self.the_ui.btn_three, QtCore.SIGNAL('clicked()'), self, QtCore.SLOT('click_three()'))
self.connect(self.the_ui.btn_four, QtCore.SIGNAL('clicked()'), self, QtCore.SLOT('click_four()'))
self.connect(self.the_ui.btn_five, QtCore.SIGNAL('clicked()'), self, QtCore.SLOT('click_five()'))
self.connect(self.the_ui.btn_six, QtCore.SIGNAL('clicked()'), self, QtCore.SLOT('click_six()'))
self.connect(self.the_ui.btn_seven, QtCore.SIGNAL('clicked()'), self, QtCore.SLOT('click_seven()'))
self.connect(self.the_ui.btn_eight, QtCore.SIGNAL('clicked()'), self, QtCore.SLOT('click_eight()'))
self.connect(self.the_ui.btn_nine, QtCore.SIGNAL('clicked()'), self, QtCore.SLOT('click_nine()'))
self.connect(self.the_ui.btn_zero, QtCore.SIGNAL('clicked()'), self, QtCore.SLOT('click_zero()'))
self.connect(self.the_ui.btn_point, QtCore.SIGNAL('clicked()'), self, QtCore.SLOT('click_point()'))
self.connect(self.the_ui.btn_add, QtCore.SIGNAL('clicked()'), self, QtCore.SLOT('click_add()'))
self.connect(self.the_ui.btn_minus, QtCore.SIGNAL('clicked()'), self, QtCore.SLOT('click_minus()'))
self.connect(self.the_ui.btn_multiply, QtCore.SIGNAL('clicked()'), self, QtCore.SLOT('click_multiply()'))
self.connect(self.the_ui.btn_divide, QtCore.SIGNAL('clicked()'), self, QtCore.SLOT('click_divide()'))
self.connect(self.the_ui.btn_equal, QtCore.SIGNAL('clicked()'), self, QtCore.SLOT('click_equal()')) @QtCore.pyqtSlot()
def click_one(self):
if self.opera == 0:
self.num1 += "1"
self.the_ui.lineEdit.setText(self.num1)
else:
self.num2 += "1"
self.the_ui.lineEdit.setText(self.num2) @QtCore.pyqtSlot()
def click_two(self):
if self.opera == 0:
self.num1 += "2"
self.the_ui.lineEdit.setText(self.num1)
else:
self.num2 += "2"
self.the_ui.lineEdit.setText(self.num2) @QtCore.pyqtSlot()
def click_three(self):
if self.opera == 0:
self.num1 += "3"
self.the_ui.lineEdit.setText(self.num1)
else:
self.num2 += "3"
self.the_ui.lineEdit.setText(self.num2) @QtCore.pyqtSlot()
def click_four(self):
if self.opera == 0:
self.num1 += "4"
self.the_ui.lineEdit.setText(self.num1)
else:
self.num2 += "4"
self.the_ui.lineEdit.setText(self.num2) @QtCore.pyqtSlot()
def click_five(self):
if self.opera == 0:
self.num1 += "5"
self.the_ui.lineEdit.setText(self.num1)
else:
self.num2 += "5"
self.the_ui.lineEdit.setText(self.num2) @QtCore.pyqtSlot()
def click_six(self):
if self.opera == 0:
self.num1 += "6"
self.the_ui.lineEdit.setText(self.num1)
else:
self.num2 += "6"
self.the_ui.lineEdit.setText(self.num2) @QtCore.pyqtSlot()
def click_seven(self):
if self.opera == 0:
self.num1 += "7"
self.the_ui.lineEdit.setText(self.num1)
else:
self.num2 += "7"
self.the_ui.lineEdit.setText(self.num2) @QtCore.pyqtSlot()
def click_eight(self):
if self.opera == 0:
self.num1 += "8"
self.the_ui.lineEdit.setText(self.num1)
else:
self.num2 += "8"
self.the_ui.lineEdit.setText(self.num2) @QtCore.pyqtSlot()
def click_nine(self):
if self.opera == 0:
self.num1 += "9"
self.the_ui.lineEdit.setText(self.num1)
else:
self.num2 += "9"
self.the_ui.lineEdit.setText(self.num2) @QtCore.pyqtSlot()
def click_zero(self):
if self.opera == 0:
if len(self.num1) != 0:
self.num1 += "0"
self.the_ui.lineEdit.setText(self.num1)
else:
if len(self.num2) != 0:
self.num2 += "0"
self.the_ui.lineEdit.setText(self.num2) @QtCore.pyqtSlot()
def click_point(self):
if self.opera == 0:
if len(self.num1) != 0:
if self.point1 == 0:
self.num1 += "."
self.the_ui.lineEdit.setText(self.num1)
self.point1 = 1
else:
if len(self.num2) != 0:
if self.point2 == 0:
self.num2 += "."
self.the_ui.lineEdit.setText(self.num2)
self.point2 = 1 @QtCore.pyqtSlot()
def click_add(self):
self.opera = 1
self.opera_add = 1
self.opera_minus = 0
self.opera_mul = 0
self.opera_div = 0
self.the_ui.lineEdit.setText("") @QtCore.pyqtSlot()
def click_minus(self):
self.opera = 1
self.opera_add = 0
self.opera_minus = 1
self.opera_mul = 0
self.opera_div = 0
self.the_ui.lineEdit.setText("") @QtCore.pyqtSlot()
def click_multiply(self):
self.opera = 1
self.opera_add = 0
self.opera_minus = 0
self.opera_mul = 1
self.opera_div = 0
self.the_ui.lineEdit.setText("") @QtCore.pyqtSlot()
def click_divide(self):
self.opera = 1
self.opera_add = 0
self.opera_minus = 0
self.opera_mul = 0
self.opera_div = 1
self.the_ui.lineEdit.setText("") @QtCore.pyqtSlot()
def click_equal(self):
if self.opera_add == 1:
self.the_ui.lineEdit.setText(str(float(self.num1) + float(self.num2)))
if self.opera_minus == 1:
self.the_ui.lineEdit.setText(str(float(self.num1) - float(self.num2)))
if self.opera_mul == 1:
self.the_ui.lineEdit.setText(str(float(self.num1) * float(self.num2)))
if self.opera_div == 1:
self.the_ui.lineEdit.setText(str(float(self.num1) / float(self.num2))) self.num1 = ""
self.num2 = ""
self.point1 = 0
self.point2 = 0
self.opera = 0
self.opera_add = 0
self.opera_minus = 0
self.opera_mul = 0
self.opera_div = 0 app = QtGui.QApplication(sys.argv)
wi = MyWidget()
wi.show()
app.exec_()

PyQt4(简单计算器)的更多相关文章

  1. 1.C#WinForm基础制作简单计算器

    利用c#语言编写简单计算器: 核心知识点: MessageBox.Show(Convert.ToString(comboBox1.SelectedIndex));//下拉序号 MessageBox.S ...

  2. 菜鸟学Android编程——简单计算器《一》

    菜鸟瞎搞,高手莫进 本人菜鸟一枚,最近在学Android编程,网上看了一些视频教程,于是想着平时手机上的计算器应该很简单,自己何不尝试着做一个呢? 于是就冒冒失失的开撸了. 简单计算器嘛,功能当然很少 ...

  3. PAT 06-1 简单计算器

    想看一般简单计算器实现的看客不好意思了,这不是你想要点东西,此处题设为“只能进行加减乘除”.“都是整数”.”优先级相同“和"从左到右".此题来自PAT(http://www.pat ...

  4. php大力力 [005节] php大力力简单计算器001

    2015-08-22 php大力力005. php大力力简单计算器001: 上网看视频,看了半天,敲击代码,如下: <html> <head> <title>简单计 ...

  5. PHP实现简单计算器

    <!--简单的计算器--> <!DOCTYPE html> <html> <head> <title>PHP实现简单计算器</titl ...

  6. c#部分---网吧充值系统;简易的闹钟;出租车计费;简单计算器;对战游戏;等额本金法计算贷款还款利息等;随机生成10个不重复的50以内的整数;推箱子;

    网吧充值系统namespace ConsoleApplication1 { class Program { struct huiyuan { public string name; public st ...

  7. JavaWeb学习记录(二十)——Model1模式(javaBean+jsp)实现简单计算器案例

    ¨JSP技术提供了三个关于JavaBean组件的动作元素,即JSP标签,它们分别为: ¨<jsp:useBean>标签:用于在JSP页面中查找或实例化一个JavaBean组件. ¨< ...

  8. 一个用WPF做的简单计算器源代码

    一.界面设计XAML代码 <Window x:Class="fengjisuanqi.MainWindow" xmlns="http://schemas.micro ...

  9. hdu 1237 简单计算器

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1237 简单计算器 Description 读入一个只包含 +, -, *, / 的非负整数计算表达式, ...

  10. 李洪强漫谈iOS开发[C语言-042]-简单计算器

    李洪强漫谈iOS开发[C语言-042]-简单计算器

随机推荐

  1. (转)Python中集合(set)的基本操作以及一些常见的用法

    原文:http://blog.51cto.com/10616534/1944841 Python除了List.Tuple.Dict等常用数据类型外,还有一种数据类型叫做集合(set),集合的最大特点是 ...

  2. 最全面的 Android 编码规范指南

    最全面的 Android 编码规范指南 本文word文档下载地址:http://pan.baidu.com/s/1bXT75O 1. 前言 这份文档参考了 Google Java 编程风格规范和 Go ...

  3. 【原】中文Ubuntu主目录下的文档文件夹改回英文

    想把中文Ubuntu主目录下的文档文件夹改回英文,在Terminal下面操作的时候要输入中文特别不方便,于是便用了更改名字的想法 方法一: 首先把那几个中文名称修改成相应的英文,比如 Desktop. ...

  4. svn 服务器搭建 ,采用http的方式加密用户。

    1.1安装svn 1.环境 centos6.5 本地ip:192.168.2.154 2.安装 yum install subversion 查看版本 svnserve --version 3.创建版 ...

  5. 【好书分享】容器网络到kubernetes网络

    Nginx 公司的 Michael Hausenblas 发布了一本关于 docker 和 kubernetes 中的容器网络的小册子.这份资料一共 72 页,是大家由浅入深的了解 Docker 和 ...

  6. java学习--Reflection反射机制

    JAVA反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法:对于任意一个对象,都能够调用它的任意方法和属性:这种动态获取信息以及动态调用对象方法的功能称为java语言的反射机制. ...

  7. GBDT多分类示例

    相当于每次都是用2分类,然后不停的训练,最后把所有的弱分类器来进行汇总 样本编号 花萼长度(cm) 花萼宽度(cm) 花瓣长度(cm) 花瓣宽度 花的种类 1 5.1 3.5 1.4 0.2 山鸢尾 ...

  8. 鹅厂优文 | ReactJS一点通

    欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由鹅厂新鲜事儿发表于云+社区专栏 作者:卢文喆 腾讯云 UI工程师 导语 | 当React 刚开始红的时候,一直觉得 JSX 的设计思想 ...

  9. css揭秘

    一:渐变 线性渐变(Linear Gradients)- 向下/向上/向左/向右/对角方向       background: linear-gradient(direction, color-sto ...

  10. Tornado简介

    Tornado是一个具有强大异步功能的Python Web框架. Hello World 使用pip安装tornado: pip install tornado 编写控制器: import torna ...