首页 > 其他分享 >计算1

计算1

时间:2022-12-27 16:02:39浏览次数:29  
标签:checkBox 进制 Form win self 计算 print

# -*- coding: utf-8 -*
import ctypes
import struct
import time
from PyQt5 import QtCore, QtGui

from PyQt5.QtCore import QEventLoop, QTimer, QThread
from PyQt5.QtGui import QColor

from untitled19 import Ui_Form

import sys

import fraction
# from PyQt5 import QtCore
from PyQt5.QtWidgets import QApplication, QMainWindow, QColorDialog


class Cmdzl():
def xf(self):
try:
self.run1()
self.run2()
self.run3()
self.run4()
self.run5()
self.run6()
self.run7()
self.run8()
time.sleep(0.5)
col2 = QColor(255,0,0)
win.pushButton.setStyleSheet("QWidget { background-color: %s }" % col2.name())

except:
print("输入格式错误")


def run1(self):
if win.checkBox.isChecked() == True:
t = win.lineEdit.text()

if win.comboBox.currentText()=='16进制转10进制':
t16 = (int(int(t, 16)))
print(t,"(的16进制转10进制)=", t16)
elif win.comboBox.currentText()=='16进制转2进制':
t16 = (int(int(t, 16)))
t16_2 = bin(t16)
print(t, "(的16进制转 2进制)=", t16_2)
elif win.comboBox.currentText() == '16进制转ASSCII':
t16 = (int(int(t, 16)))
t16_ASS = chr(int(t16))
print(t, "(16进制对应的ASCII码字符)=",t16_ASS)
elif win.comboBox.currentText() == '10进制转16进制':
col2 = QColor(0, 255, 0)
win.label_3.setStyleSheet("QWidget { background-color: %s }" % col2.name())
t10 = (int(int(t, 10)))
t10_16 = hex(t10)
print(t, "(的10进制转16进制)=", t10_16)
elif win.comboBox.currentText() == '10进制转2进制':
t10 = (int(int(t, 10)))
t10_2 = bin(t10)[2:]
print(t, "(的10进制转 2进制)=", t10_2)
elif win.comboBox.currentText() == '10进制转ASSCII':
tAS = chr(int(t))
print(t, "(10进制对应的ASCII码字符)=", tAS)
elif win.comboBox.currentText() == '2进制转10进制':
t2 = int(t, 2)
print(t, "(2进制的10进制)=", t2)
elif win.comboBox.currentText() == '2进制转16进制':
t2_10 = int(t, 2)
t2_16 = hex(t2_10)
print(t, "(2进制的16进制)=", t2_16)
elif win.comboBox.currentText() == '2进制转ASSCII':
t2_10 = int(t, 2)
t2_ASSCII = chr(int(t2_10))
print(t, "(2进制对应的ASCII码字符为)=",t2_ASSCII)
elif win.comboBox.currentText() == 'ASCII码转10进制':
ASCII_10 = ord(t)
print(t, "(ASCII码转10进制)=", ASCII_10)
elif win.comboBox.currentText() == 'ASCII码转16进制':
ASCII_10 = ord(t)
ASCCII_16 = hex(ASCII_10)
print(t, "(ASCII码转16进制)=", ASCCII_16)
elif win.comboBox.currentText() == 'ASCII码转2进制':
ASCII_10 = ord(t)
ASSCII_2 = bin(ASCII_10)
print(t, "(ASCII码转 2进制)=", ASSCII_2)
elif win.comboBox.currentText() == '小数转单精度':

d=self.float_to_hex(float(t)).upper()

print(t, "(小数转单精度)=", d)
elif win.comboBox.currentText() == '小数转双精度':
d = self.double_to_hex(float(t)).upper()

print(t, "(小数转双精度)=", d)
elif win.comboBox.currentText() == 'hex单精度转小数':
d = self.hex2float(str(t))

print(t, "(16进制单精度转小数)=", d)
elif win.comboBox.currentText() == 'hex双精度转小数':
d = self.hexToDouble(str(t))

print(t, "(16进制双精度转小数)=", d)
else:
pass
def float_to_hex(self, f):
return hex(struct.unpack('<I', struct.pack('<f', f))[0])
def double_to_hex(self, f):
return hex(struct.unpack('<Q', struct.pack('<d', f))[0])
def hex2float(self,h):
i = int(h, 16)
cp = ctypes.pointer(ctypes.c_int(i))
fp = ctypes.cast(cp, ctypes.POINTER(ctypes.c_float))
return fp.contents.value
def hexToDouble(self,hexString): # 16进制转double
return struct.unpack('>d', bytes.fromhex(hexString))[0]

def run2(self):
if win.checkBox_2.isChecked() == True:
t = win.lineEdit.text()
if win.comboBox_2.currentText() =="法拉(F)":
t1 = int(t)
t2 = t1 * 1000
t3 = t1 * 1000* 1000
t4 = t1 * 1000 * 1000* 1000
t5 = t1 * 1000 * 1000 * 1000* 1000
print(t, "法拉(F)", '=', t2, '毫法(mF)')
print(t, "法拉(F)", '=', t3, '微法(μF)')
print(t, "法拉(F)", '=', t4, '纳法(nF)')
print(t, "法拉(F)", '=', t5, '皮法(pF)')
if win.comboBox_2.currentText() == "毫法(mF)":
t1 = int(t)
t2 = t1 / 1000
t3 = t1 * 1000
t4 = t1 * 1000 * 1000
t5 = t1 * 1000 * 1000 * 1000
print(t, "毫法(mF)", '=', t2, '法拉(F)')
print(t, "毫法(mF)", '=', t3, '微法(μF)')
print(t, "毫法(mF)", '=', t4, '纳法(nF)')
print(t, "毫法(mF)", '=', t5, '皮法(pF)')
if win.comboBox_2.currentText() == "微法(μF)":
t1 = int(t)
t2 = t1 / (1000 * 1000)
t3 = t1 / 1000
t4 = t1 * 1000
t5 = t1 * 1000 * 1000
print(t, "微法(μF)", '=', t2, '法拉(F)')
print(t, "微法(μF)", '=', t3, '毫法(mF)')
print(t, "微法(μF)", '=', t4, '纳法(nF)')
print(t, "微法(μF)", '=', t5, '皮法(pF)')
if win.comboBox_2.currentText() == "纳法(nF)":
t1 = int(t)
t2 = t1 / (1000 * 1000 * 1000)
t3 = t1 / (1000 * 1000)
t4 = t1 / 1000
t5 = t1 * 1000
d = '纳法(nF)'
print(t, d, '=', t2, '法拉(F)')
print(t, d, '=', t3, '毫法(mF)')
print(t, d, '=', t4, '微法(μF)')
print(t, d, '=', t5, '皮法(pF)')
if win.comboBox_2.currentText() == "皮法(pF)":
t1 = int(t)
t2 = t1 / (1000 * 1000 * 1000 * 1000)
t3 = t1 / (1000 * 1000 * 1000)
t4 = t1 / (1000 * 1000)
t5 = t1 / 1000
d = '皮法(pF)'
print(t, d, '=', t2, '法拉(F)')
print(t, d, '=', t3, '毫法(mF)')
print(t, d, '=', t4, '微法(μF)')
print(t, d, '=', t5, '纳法(nF)')
print('\n')
def run3(self):
if win.checkBox_5.isChecked() == True:
t = win.lineEdit.text()
t2 = win.lineEdit_2.text()
t3 = float(t) + float(t2)
print(t, "+", t2, '=', t3)

def run4(self):
if win.checkBox_6.isChecked() == True:
t = win.lineEdit.text()
t2 = win.lineEdit_2.text()
t3 = float(t) - float(t2)
print(t, "-", t2, '=', t3)

def run5(self):
if win.checkBox_7.isChecked() == True:
t = win.lineEdit.text()
t2 = win.lineEdit_2.text()
t3 = float(t) * float(t2)
print(t, "×", t2, '=', t3)

def run6(self):
if win.checkBox_8.isChecked() == True:
t = win.lineEdit.text()
t2 = win.lineEdit_2.text()
t3 = float(t) / float(t2)
print(t, "÷", t2, '=', t3)

def run7(self):
if win.checkBox_3.isChecked() == True:
t = float(win.lineEdit.text())
t2 =int( win.lineEdit_2.text())
# print(t,'的',t2, "次方")
t3 =pow(t, t2)

print(t,'(的)',t2, "(次方)", '=', t3)
def run8(self):
if win.checkBox_4.isChecked() == True:
t = float(win.lineEdit.text())
t2 =int(win.lineEdit_2.text())
t3 =float(1/t2)
t4 =pow(t, t3)
print(t,"(的根号"
""
""
""
")",t2 ,"(次方)", '=', t4)



class ControlBoard(QMainWindow, Ui_Form):
def __init__(self):
super(ControlBoard, self).__init__()
self.setupUi(self)
# 下面将输出重定向到textBrowser中
sys.stdout = EmittingStr(textWritten=self.outputWritten)
sys.stderr = EmittingStr(textWritten=self.outputWritten)
self.pushButton.clicked.connect(self.bClicked)
self.checkBox_9.stateChanged.connect(self.run20)
self.initUI()

def initUI(self):
self.下拉框()
self.下拉框2()
self.coclor()
def outputWritten(self, text):
cursor = self.textEdit_2.textCursor()
cursor.movePosition(QtGui.QTextCursor.End)
cursor.insertText(text)
self.textEdit_2.setTextCursor(cursor)
self.textEdit_2.ensureCursorVisible()
def bClicked(self):
t = runThread(self)
t.start()
self.textEdit_2.setText("")

def coclor(self):
# col = QColor(255, 0, 0)
self.btn4 = self.pushButton
self.btn4.clicked.connect(self.showDialog4)
# self.pushButton.setStyleSheet("QWidget { background-color: %s }" % col.name())
def showDialog4(self):
col = QColor(0, 255,0)

start_time = time.time()
if col.isValid():
self.pushButton.setStyleSheet("QWidget { background-color: %s }" % col.name())

def run20(self):
if win.checkBox_9.isChecked() == False:
self.checkBox.setChecked(False)
self.checkBox_2.setChecked(False)
self.checkBox_3.setChecked(False)
self.checkBox_4.setChecked(False)
self.checkBox_5.setChecked(False)
self.checkBox_6.setChecked(False)
self.checkBox_7.setChecked(False)
self.checkBox_8.setChecked(False)
else:
self.checkBox.setChecked(True)
def 下拉框(self):
combo = self.comboBox
combo.addItem("16进制转10进制")
combo.addItem("16进制转2进制")
combo.addItem("16进制转ASSCII")
combo.addItem("10进制转16进制")
combo.addItem("10进制转2进制")
combo.addItem("10进制转ASSCII")
combo.addItem("2进制转10进制")
combo.addItem("2进制转16进制")
combo.addItem("2进制转ASSCII")
combo.addItem("ASCII码转10进制")
combo.addItem("ASCII码转16进制")
combo.addItem("ASCII码转2进制")
combo.addItem("小数转单精度")
combo.addItem("小数转双精度")
combo.addItem("hex单精度转小数")
combo.addItem("hex双精度转小数")

combo.activated[str].connect(self.onActivated)
def 下拉框2(self):
combo2 = self.comboBox_2
combo2.addItem("法拉(F)")
combo2.addItem("毫法(mF)")
combo2.addItem("微法(μF)")
combo2.addItem("纳法(nF)")
combo2.addItem("皮法(pF)")
combo2.activated[str].connect(self.onActivated)
def onActivated(self, text):
self.label_3.setText(text)
self.label_3.adjustSize()
# self.textEdit.setText(text)

def exceptOutConfig(exctype, value, tb):
print('My Error Information:')
print('Type:', exctype)
print('Value:', value)
print('Traceback:', tb)

class EmittingStr(QtCore.QObject):
textWritten = QtCore.pyqtSignal(str) # 定义一个发送str的信号

def write(self, text):
self.textWritten.emit(str(text))

class runThread(QThread):
def run(self):
Cmdzl().xf()
# win.pushButton.setEnabled(True)

if __name__ == "__main__":

sys.excepthook = exceptOutConfig
app = QApplication(sys.argv)
win = ControlBoard()
win.show()
Cmdzl()
sys.exit(app.exec_())

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'untitled19.ui'
#
# Created by: PyQt5 UI code generator 5.15.6
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(346, 229)
self.label = QtWidgets.QLabel(Form)
self.label.setGeometry(QtCore.QRect(80, 30, 54, 12))
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(Form)
self.label_2.setGeometry(QtCore.QRect(280, 10, 41, 20))
self.label_2.setObjectName("label_2")
self.lineEdit = QtWidgets.QLineEdit(Form)
self.lineEdit.setGeometry(QtCore.QRect(10, 10, 121, 20))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit_2 = QtWidgets.QLineEdit(Form)
self.lineEdit_2.setGeometry(QtCore.QRect(142, 10, 131, 20))
self.lineEdit_2.setObjectName("lineEdit_2")
self.checkBox = QtWidgets.QCheckBox(Form)
self.checkBox.setGeometry(QtCore.QRect(10, 40, 71, 16))
self.checkBox.setObjectName("checkBox")
self.comboBox = QtWidgets.QComboBox(Form)
self.comboBox.setGeometry(QtCore.QRect(10, 60, 121, 22))
self.comboBox.setObjectName("comboBox")
self.checkBox_2 = QtWidgets.QCheckBox(Form)
self.checkBox_2.setGeometry(QtCore.QRect(10, 90, 71, 16))
self.checkBox_2.setObjectName("checkBox_2")
self.comboBox_2 = QtWidgets.QComboBox(Form)
self.comboBox_2.setGeometry(QtCore.QRect(10, 110, 121, 22))
self.comboBox_2.setObjectName("comboBox_2")
self.checkBox_3 = QtWidgets.QCheckBox(Form)
self.checkBox_3.setGeometry(QtCore.QRect(10, 180, 71, 16))
self.checkBox_3.setObjectName("checkBox_3")
self.checkBox_4 = QtWidgets.QCheckBox(Form)
self.checkBox_4.setGeometry(QtCore.QRect(60, 180, 71, 16))
self.checkBox_4.setObjectName("checkBox_4")
self.checkBox_5 = QtWidgets.QCheckBox(Form)
self.checkBox_5.setGeometry(QtCore.QRect(10, 140, 71, 16))
self.checkBox_5.setObjectName("checkBox_5")
self.checkBox_6 = QtWidgets.QCheckBox(Form)
self.checkBox_6.setGeometry(QtCore.QRect(60, 140, 71, 16))
self.checkBox_6.setObjectName("checkBox_6")
self.checkBox_7 = QtWidgets.QCheckBox(Form)
self.checkBox_7.setGeometry(QtCore.QRect(10, 160, 71, 16))
self.checkBox_7.setObjectName("checkBox_7")
self.checkBox_8 = QtWidgets.QCheckBox(Form)
self.checkBox_8.setGeometry(QtCore.QRect(60, 160, 71, 16))
self.checkBox_8.setObjectName("checkBox_8")
self.checkBox_9 = QtWidgets.QCheckBox(Form)
self.checkBox_9.setGeometry(QtCore.QRect(10, 200, 71, 16))
self.checkBox_9.setObjectName("checkBox_9")
self.textEdit_2 = QtWidgets.QTextEdit(Form)
self.textEdit_2.setGeometry(QtCore.QRect(140, 40, 201, 121))
self.textEdit_2.setObjectName("textEdit_2")
self.pushButton = QtWidgets.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(140, 200, 75, 23))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(Form)
self.pushButton_2.setGeometry(QtCore.QRect(140, 170, 75, 23))
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_3 = QtWidgets.QPushButton(Form)
self.pushButton_3.setGeometry(QtCore.QRect(230, 170, 75, 23))
self.pushButton_3.setObjectName("pushButton_3")
self.label_3 = QtWidgets.QLabel(Form)
self.label_3.setGeometry(QtCore.QRect(240, 210, 54, 12))
self.label_3.setObjectName("label_3")

self.retranslateUi(Form)
self.pushButton_2.clicked.connect(self.textEdit_2.clear) # type: ignore
self.pushButton_3.clicked.connect(Form.close) # type: ignore
QtCore.QMetaObject.connectSlotsByName(Form)

def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "计算器"))
self.label.setText(_translate("Form", "A"))
self.label_2.setText(_translate("Form", "B"))
self.checkBox.setText(_translate("Form", "进制转换"))
self.checkBox_2.setText(_translate("Form", "电容"))
self.checkBox_3.setText(_translate("Form", "平方"))
self.checkBox_4.setText(_translate("Form", "平方根"))
self.checkBox_5.setText(_translate("Form", "A+B"))
self.checkBox_6.setText(_translate("Form", "A-B"))
self.checkBox_7.setText(_translate("Form", "A×B"))
self.checkBox_8.setText(_translate("Form", "A÷B"))
self.checkBox_9.setText(_translate("Form", "反选"))
self.pushButton.setText(_translate("Form", "结果="))
self.pushButton_2.setText(_translate("Form", "清除信息"))
self.pushButton_3.setText(_translate("Form", "退出"))
self.label_3.setText(_translate("Form", "author liuzhen"))
self.lineEdit_2.setText('2')
self.lineEdit.setText('4')

标签:checkBox,进制,Form,win,self,计算,print
From: https://blog.51cto.com/u_15773623/5972896

相关文章

  • 那些年,我们一起刷过的计算机视觉比赛
    前言计算机视觉是一个对操作性和实战性要求都非常高的领域,对于许多在校的本科生/研究生,接触的项目并不算多,甚至非常单一,有的导师连项目都没有,这个时候想要深入CV领域几乎不......
  • k03_计算机基础_dos命令行
    一、Windows自带的命令行操作界面(DOS命令)二、简介在学习java的时候,我们需要下载jdk,然后安装jdk,然后配置环境变量,然后会用命令行窗口检验是否安装成功,尽管最新的jdk版本......
  • MIT——6.828:操作系统工程——第1章:实验一:启动计算机
    本实验分为三个部分。第一部分:熟悉x86汇编语言、QEMUx86模拟器和PC的开机引导程序。第二部分:检查我们的6.828内核的引导装载程序。第三部分:深入研究了我们的6.......
  • 2021中国科学院文献情报中心期刊分区表 计算机(2)
    2021中国科学院文献情报中心期刊分区表计算机(2)​​2021中国科学院文献情报中心期刊分区表(小类计算机相关)​​​​1.人工智能​​​​3区​​​​4区​​​​2.控制论​......
  • Vue3之computed计算属性
    计算属性  computed函数与Vue2.x中computed配置功能一致写法<template><h1>一个人的信息</h1>姓:<inputtype="text"v-model="person.firstName">......
  • 2021中国科学院文献情报中心期刊分区表 计算机
    2021中国科学院文献情报中心期刊分区表​​2021中国科学院文献情报中心期刊分区表(小类计算机相关)​​​​1.人工智能​​​​1区​​​​2区​​​​2.控制论​​​​1......
  • 计算领域高质量科技期刊分级目录
    2021年5月,CCF入选中国科协分领域发布高质量科技期刊分级目录项目,随后启动《计算领域高质量科技期刊分级目录》遴选工作。本次遴选的原则是:把握基础研究、应用研究等不同类型......
  • k03_计算机基础_dos命令行
    一、Windows自带的命令行操作界面(DOS命令)二、简介在学习java的时候,我们需要下载jdk,然后安装jdk,然后配置环境变量,然后会用命令行窗口检验是否安装成功,尽管最新的jdk版本......
  • 计算机网络——应用层
    文章目录​​总览:TCP/IP协议栈​​​​一.应用层概述​​​​1.1网络应用程序体系结构​​​​1.2应用层协议​​​​1.3选择运输层协议​​​​二.域名系统DNS(Domain......
  • 计算机网络——因特网上的音频视频
    一.Internet上传输音频视频面临的问题音频视频占用带宽高,要求网速恒定延迟低。而对于数据信息,对带宽要求低,网速不稳定,延迟高也没事。面临问题:延迟:发送时延,传播时延,排队时......