• <fieldset id="8imwq"><menu id="8imwq"></menu></fieldset>
  • <bdo id="8imwq"><input id="8imwq"></input></bdo>
    最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
    問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
    當前位置: 首頁 - 科技 - 知識百科 - 正文

    python3.5+PyQt5+Eric6實現的一個計算器方法(附代碼)

    來源:懂視網 責編:小采 時間:2020-11-27 14:16:23
    文檔

    python3.5+PyQt5+Eric6實現的一個計算器方法(附代碼)

    python3.5+PyQt5+Eric6實現的一個計算器方法(附代碼):這篇文章主要介紹了python3.5 + PyQt5 +Eric6實現的一個計算器方法(附代碼),在windows7 32位系統可以完美運行 計算器,有興趣的可以了解一下。目前可以實現簡單的計算。計算前請重置,設計的時候默認數字是0,學了半天就做出來個這么個結果,bug不少。
    推薦度:
    導讀python3.5+PyQt5+Eric6實現的一個計算器方法(附代碼):這篇文章主要介紹了python3.5 + PyQt5 +Eric6實現的一個計算器方法(附代碼),在windows7 32位系統可以完美運行 計算器,有興趣的可以了解一下。目前可以實現簡單的計算。計算前請重置,設計的時候默認數字是0,學了半天就做出來個這么個結果,bug不少。
    這篇文章主要介紹了python3.5 + PyQt5 +Eric6實現的一個計算器方法(附代碼),在windows7 32位系統可以完美運行 計算器,有興趣的可以了解一下。

    目前可以實現簡單的計算。計算前請重置,設計的時候默認數字是0,學了半天就做出來個這么個結果,bug不少。 python3.5 + PyQt5 +Eric6 在windows7 32位系統可以完美運行 計算器,簡單學了半天就畫個圖實現的存在bug,部分按鈕還未實現,后續優化。

    代碼結構如圖:

    python3.5 + PyQt5 +Eric6實現的一個計算器方法(附代碼)

    jisuan.py

    import re
    #匹配整數或小數的乘除法,包括了開頭存在減號的情況
    mul_p=re.compile("(-?d+)(.d+)?(*|/)(-?d+)(.d+)?")
    #匹配整數或小數的加減法,包括了開頭存在減號的情況
    plus_minus = re.compile("(-?d+)(.d+)?(-|+)(-?d+)(.d+)?")
    #匹配括號
    bracket=re.compile("([^()]*)")
    #匹配乘法的時候出現乘以負數的情況,包括了開頭存在減號的情況
    mul_minus_minus = re.compile("(-?d+)(.d+)?(*-)(d+)(.d+)?")
    #匹配除法的時候出現乘以負數的情況,包括了開頭存在減號的情況
    p_minus_minus = re.compile("(-?d+)(.d+)?(/-)(d+)(.d+)?")
    #定義一個兩位數的加減乘除法的運算,匹配左邊的右邊的數字和左邊的數字,然后進行計算
    def touble_cale(str_expire):
     if str_expire.count("+") == 1:
     right_num = float(str_expire[(str_expire.find("+")+1):])
     left_num = float(str_expire[:str_expire.find("+")])
     return str(right_num+left_num)
     elif str_expire[1:].count("-") == 1:
     right_num = float(str_expire[:str_expire.find("-",1)])
     left_num = float(str_expire[(str_expire.find("-", 1) + 1):])
     return str(right_num - left_num)
     elif str_expire.count("*") == 1:
     right_num = float(str_expire[:str_expire.find("*")])
     left_num = float(str_expire[(str_expire.find("*")+1):])
     return str(right_num * left_num)
     elif str_expire.count("/") == 1:
     right_num = float(str_expire[:str_expire.find("/")])
     left_num = float(str_expire[(str_expire.find("/") + 1):])
     return str(right_num / left_num)
    
    
    #定義一個方法用于判斷是否存在乘以負數和除以負數的情況
    def judge_mul_minus(str_expire):
     #判斷公式中乘以負數的部分
     if len(re.findall("(*-)", str_expire)) != 0:
     #調用上面的正則取得*-的公式
     temp_mul_minus = mul_minus_minus.search(str_expire).group()
     #將匹配的部分的*-換成*并將-放到前面
     temp_mul_minus_2 = temp_mul_minus.replace(temp_mul_minus,"-" + temp_mul_minus.replace("*-","*"))
     #經更改的的部分與原來的部分進行替換
     str_expire=str_expire.replace(temp_mul_minus,temp_mul_minus_2)
     return judge_mul_minus(str_expire)
     #return str_expire
     # 判斷公式中除以負數的部分
     elif len(re.findall(r"(/-)", str_expire)) != 0:
     # 調用上面的正則取得/-的公式
     temp_dev_minus = p_minus_minus.search(str_expire).group()
     # 將匹配的部分的/-換成/并將-放到前面
     temp_dev_minus_2 = temp_dev_minus.replace(temp_dev_minus,"-" + temp_dev_minus.replace("/-","/"))
     # 經更改的的部分與原來的部分進行替換
     str_expire = str_expire.replace(temp_dev_minus,temp_dev_minus_2)
     return judge_mul_minus(str_expire)
     #調用change_sign將公式中的++換成= +-換成-
     return change_sign(str_expire)
    
    #定義一個方法取將--更改為+ +-改為-
    def change_sign(str_expire):
     if len(re.findall(r"(+-)", str_expire)) != 0:
     str_expire = str_expire.replace("+-", "-")
     return change_sign(str_expire)
     elif len(re.findall(r"(--)", str_expire)) != 0:
     str_expire = str_expire.replace("--", "+")
     return change_sign(str_expire)
     return str_expire
    
    
    #定義一個方法用于計算只有加減乘除的公式,優先處理乘法
    def cale_mix(str_expire):
     #如果公式中出現符號數字的情況即+5 -6 *8 /8的這種情況直接放回數字否則則先計算乘除在處理加減
     while len(re.findall("[-+*/]",str_expire[1:])) != 0:
     if len(re.findall("(*|/)",str_expire)) != 0:
     str_expire = str_expire.replace(mul_p.search(str_expire).group(),touble_cale(mul_p.search(str_expire).group()))
     elif len(re.findall("(+|-)",str_expire)) !=0:
     str_expire = str_expire.replace(plus_minus.search(str_expire).group(),touble_cale(plus_minus.search(str_expire).group()))
     return str_expire
    
    #定義一個方法用于去括號,并調用上述的方法進行計算
    def remove_bracket(str_expire):
     #判斷公式中是否有括號
     if len(bracket.findall(str_expire)) == 0:
     return cale_mix(judge_mul_minus(str_expire))
     elif len(bracket.findall(str_expire))!=0:
     while len(bracket.findall(str_expire)) !=0:
     #print(bracket.search(str_expire).group())
     #只有存在括號優先處理括號中的內容并對內容進行替換,直到沒有括號位置
     str_expire = str_expire.replace(bracket.search(str_expire).group(),cale_mix(judge_mul_minus(bracket.search(str_expire).group()[1:-1])))
     str_expire = cale_mix(judge_mul_minus(str_expire))
     return str_expire
    if name == "main":
     while True:
     user_input_expire = input("請輸入你的公式:(不要帶空格,q表示退出):")
     print("%s=%s" %(user_input_expire,remove_bracket(user_input_expire)))
     continue

    untitled.py

    # -*- coding: utf-8 -*-
    from PyQt5.QtCore import *
    from PyQt5.QtWidgets import *
    from PyQt5 import QtCore, QtGui, QtWidgets
    from Ui_untitled import Ui_Dialog
    from jisuan import remove_bracket
    class Dialog(QDialog, Ui_Dialog):
     def init(self, parent=None):
     super(Dialog, self).init(parent)
     self.setupUi(self)
     @pyqtSlot()
     def on_Button_6_clicked(self):
     self.Edit_xianshi.insertPlainText('6')
     @pyqtSlot()
     def on_Button_2_clicked(self):
     self.Edit_xianshi.insertPlainText('2')
     @pyqtSlot()
     def on_Button_3_clicked(self):
     self.Edit_xianshi.insertPlainText('3')
     @pyqtSlot()
     def on_Button_pingfang_clicked(self):
     me=self.Edit_xianshi.toPlainText()
     m=int(me) *int(me)
     self.Edit_xianshi.clear()
     self.Edit_xianshi.append(str(m))
     @pyqtSlot()
     def on_Button_add_clicked(self):
     h=self.Edit_xianshi.toPlainText()
     self.Edit_xianshi.clear()
     self.Edit_xianshi.append(h+'+')
     @pyqtSlot()
     def on_Button_jian_clicked(self):
     h = self.Edit_xianshi.toPlainText()
     self.Edit_xianshi.clear()
     self.Edit_xianshi.append(h + '-')
     @pyqtSlot()
     def on_Button_9_clicked(self):
     self.Edit_xianshi.insertPlainText('9')
     @pyqtSlot()
     def on_Button_chu_clicked(self):
     h = self.Edit_xianshi.toPlainText()
     self.Edit_xianshi.clear()
     self.Edit_xianshi.append(h + '/')
     @pyqtSlot()
     def on_Button_cheng_clicked(self):
     h = self.Edit_xianshi.toPlainText()
     self.Edit_xianshi.clear()
     self.Edit_xianshi.append(h + '*')
     @pyqtSlot()
     def on_Button_8_clicked(self):
     self.Edit_xianshi.insertPlainText('8')
     @pyqtSlot()
     def on_Button_4_clicked(self):
     self.Edit_xianshi.insertPlainText('4')
     @pyqtSlot()
     def on_Button_esc_clicked(self):
     self.Edit_xianshi.clear()
     @pyqtSlot()
     def on_Button_7_clicked(self):
     self.Edit_xianshi.insertPlainText('7')
     @pyqtSlot()
     def on_Button_1_clicked(self):
     self.Edit_xianshi.insertPlainText('1')
     @pyqtSlot()
     def on_Button_5_clicked(self):
     self.Edit_xianshi.insertPlainText('5')
     @pyqtSlot()
     def on_Button_xiaoshu_clicked(self):
     self.Edit_xianshi.insertPlainText('.')
     @pyqtSlot()
     def on_Button_0_clicked(self):
     self.Edit_xianshi.insertPlainText('0')
     @pyqtSlot()
     def on_Button_dengyu_clicked(self):
     pe=self.Edit_xianshi.toPlainText()
     m=remove_bracket(pe)
     self.Edit_xianshi.clear()
     self.Edit_xianshi.append(str(m))
    
     def on_Button_fenzhi_clicked(self):
     pe = self.Edit_xianshi.toPlainText()
     if int(pe) ==0:
     QMessageBox.information(self,u'提示',u'零不能作為分母')
     Dialog()
     else:
     m=1/(int(pe))
     self.Edit_xianshi.clear()
     self.Edit_xianshi.append(str(m))
     Dialog()
    if name =="main":
     import sys
     app = QtWidgets.QApplication(sys.argv)
     app.processEvents()
     ui = Dialog()
     ui.show()
    
     sys.exit(app.exec_())

    Ui_untitled.py

    # -*- coding: utf-8 -*-
    
    # Form implementation generated from reading ui file 'C:UsersAdministratorDesktoppyqt5untitled.ui'
    #
    # Created by: PyQt5 UI code generator 5.5
    #
    # WARNING! All changes made in this file will be lost!
    
    from PyQt5 import QtCore, QtGui, QtWidgets
    
    class Ui_Dialog(object):
     def setupUi(self, Dialog):
     Dialog.setObjectName("Dialog")
     Dialog.resize(357, 320)
     Dialog.setStyleSheet("font: 75 16pt "Aharoni";
    "
    "background-color: rgb(206, 255, 251);")
     self.label = QtWidgets.QLabel(Dialog)
     self.label.setGeometry(QtCore.QRect(201, 210, 301, 21))
     self.label.setText("")
     self.label.setObjectName("label")
     self.Edit_xianshi = QtWidgets.QTextEdit(Dialog)
     self.Edit_xianshi.setGeometry(QtCore.QRect(0, 0, 351, 41))
     self.Edit_xianshi.setStyleSheet("font: 75 16pt "Aharoni";")
     self.Edit_xianshi.setObjectName("Edit_xianshi")
     self.gridLayoutWidget = QtWidgets.QWidget(Dialog)
     self.gridLayoutWidget.setGeometry(QtCore.QRect(0, 30, 351, 281))
     self.gridLayoutWidget.setObjectName("gridLayoutWidget")
     self.gridLayout = QtWidgets.QGridLayout(self.gridLayoutWidget)
     self.gridLayout.setObjectName("gridLayout")
     self.Button_6 = QtWidgets.QPushButton(self.gridLayoutWidget)
     self.Button_6.setObjectName("Button_6")
     self.gridLayout.addWidget(self.Button_6, 2, 2, 1, 1)
     self.Button_2 = QtWidgets.QPushButton(self.gridLayoutWidget)
     self.Button_2.setObjectName("Button_2")
     self.gridLayout.addWidget(self.Button_2, 3, 1, 1, 1)
     self.Button_3 = QtWidgets.QPushButton(self.gridLayoutWidget)
     self.Button_3.setObjectName("Button_3")
     self.gridLayout.addWidget(self.Button_3, 3, 2, 1, 1)
     self.Button_fenzhi = QtWidgets.QPushButton(self.gridLayoutWidget)
     self.Button_fenzhi.setObjectName("Button_fenzhi")
     self.gridLayout.addWidget(self.Button_fenzhi, 1, 3, 1, 1)
     self.Button_pingfang = QtWidgets.QPushButton(self.gridLayoutWidget)
     self.Button_pingfang.setObjectName("Button_pingfang")
     self.gridLayout.addWidget(self.Button_pingfang, 0, 3, 1, 1)
     self.Button_add = QtWidgets.QPushButton(self.gridLayoutWidget)
     self.Button_add.setObjectName("Button_add")
     self.gridLayout.addWidget(self.Button_add, 2, 3, 1, 1)
     self.Button_jian = QtWidgets.QPushButton(self.gridLayoutWidget)
     self.Button_jian.setObjectName("Button_jian")
     self.gridLayout.addWidget(self.Button_jian, 3, 3, 1, 1)
     self.Button_9 = QtWidgets.QPushButton(self.gridLayoutWidget)
     self.Button_9.setObjectName("Button_9")
     self.gridLayout.addWidget(self.Button_9, 1, 2, 1, 1)
     self.Button_chu = QtWidgets.QPushButton(self.gridLayoutWidget)
     self.Button_chu.setObjectName("Button_chu")
     self.gridLayout.addWidget(self.Button_chu, 0, 2, 1, 1)
     self.Button_cheng = QtWidgets.QPushButton(self.gridLayoutWidget)
     self.Button_cheng.setObjectName("Button_cheng")
     self.gridLayout.addWidget(self.Button_cheng, 0, 1, 1, 1)
     self.Button_8 = QtWidgets.QPushButton(self.gridLayoutWidget)
     self.Button_8.setObjectName("Button_8")
     self.gridLayout.addWidget(self.Button_8, 1, 1, 1, 1)
     self.Button_4 = QtWidgets.QPushButton(self.gridLayoutWidget)
     self.Button_4.setObjectName("Button_4")
     self.gridLayout.addWidget(self.Button_4, 2, 0, 1, 1)
     self.Button_esc = QtWidgets.QPushButton(self.gridLayoutWidget)
     self.Button_esc.setObjectName("Button_esc")
     self.gridLayout.addWidget(self.Button_esc, 0, 0, 1, 1)
     self.Button_7 = QtWidgets.QPushButton(self.gridLayoutWidget)
     self.Button_7.setObjectName("Button_7")
     self.gridLayout.addWidget(self.Button_7, 1, 0, 1, 1)
     self.Button_1 = QtWidgets.QPushButton(self.gridLayoutWidget)
     self.Button_1.setObjectName("Button_1")
     self.gridLayout.addWidget(self.Button_1, 3, 0, 1, 1)
     self.Button_5 = QtWidgets.QPushButton(self.gridLayoutWidget)
     self.Button_5.setObjectName("Button_5")
     self.gridLayout.addWidget(self.Button_5, 2, 1, 1, 1)
     self.pushButton_17 = QtWidgets.QPushButton(self.gridLayoutWidget)
     self.pushButton_17.setText("")
     self.pushButton_17.setObjectName("pushButton_17")
     self.gridLayout.addWidget(self.pushButton_17, 4, 0, 1, 1)
     self.Button_xiaoshu = QtWidgets.QPushButton(self.gridLayoutWidget)
     self.Button_xiaoshu.setObjectName("Button_xiaoshu")
     self.gridLayout.addWidget(self.Button_xiaoshu, 4, 1, 1, 1)
     self.Button_0 = QtWidgets.QPushButton(self.gridLayoutWidget)
     self.Button_0.setStyleSheet("")
     self.Button_0.setObjectName("Button_0")
     self.gridLayout.addWidget(self.Button_0, 4, 2, 1, 1)
     self.Button_dengyu = QtWidgets.QPushButton(self.gridLayoutWidget)
     self.Button_dengyu.setObjectName("Button_dengyu")
     self.gridLayout.addWidget(self.Button_dengyu, 4, 3, 1, 1)
    
     self.retranslateUi(Dialog)
     QtCore.QMetaObject.connectSlotsByName(Dialog)
    
     def retranslateUi(self, Dialog):
     _translate = QtCore.QCoreApplication.translate
     Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
     self.Edit_xianshi.setHtml(_translate("Dialog", "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
    "
    "<html><head><meta name="qrichtext" content="1" /><style type="text/css">
    "
    "p, li { white-space: pre-wrap; }
    "
    "</style></head><body style=" font-family:'Aharoni'; font-size:16pt; font-weight:72; font-style:normal;">
    "
    "<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'SimSun'; font-weight:400;">0</span></p></body></html>"))
     self.Button_6.setText(_translate("Dialog", "6"))
     self.Button_2.setText(_translate("Dialog", "2"))
     self.Button_3.setText(_translate("Dialog", "3"))
     self.Button_fenzhi.setText(_translate("Dialog", "1/^"))
     self.Button_pingfang.setText(_translate("Dialog", "^2"))
     self.Button_add.setText(_translate("Dialog", "+"))
     self.Button_jian.setText(_translate("Dialog", "-"))
     self.Button_9.setText(_translate("Dialog", "9"))
     self.Button_chu.setText(_translate("Dialog", "/"))
     self.Button_cheng.setText(_translate("Dialog", "*"))
     self.Button_8.setText(_translate("Dialog", "8"))
     self.Button_4.setText(_translate("Dialog", "4"))
     self.Button_esc.setText(_translate("Dialog", "esc"))
     self.Button_7.setText(_translate("Dialog", "7"))
     self.Button_1.setText(_translate("Dialog", "1"))
     self.Button_5.setText(_translate("Dialog", "5"))
     self.Button_xiaoshu.setText(_translate("Dialog", "."))
     self.Button_0.setText(_translate("Dialog", "0"))
     self.Button_dengyu.setText(_translate("Dialog", "="))
    
    
    if name == "main":
     import sys
     app = QtWidgets.QApplication(sys.argv)
     Dialog = QtWidgets.QDialog()
     ui = Ui_Dialog()
     ui.setupUi(Dialog)
     Dialog.show()
     sys.exit(app.exec_())

    效果圖:

    python3.5 + PyQt5 +Eric6實現的一個計算器方法(附代碼)

    聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

    文檔

    python3.5+PyQt5+Eric6實現的一個計算器方法(附代碼)

    python3.5+PyQt5+Eric6實現的一個計算器方法(附代碼):這篇文章主要介紹了python3.5 + PyQt5 +Eric6實現的一個計算器方法(附代碼),在windows7 32位系統可以完美運行 計算器,有興趣的可以了解一下。目前可以實現簡單的計算。計算前請重置,設計的時候默認數字是0,學了半天就做出來個這么個結果,bug不少。
    推薦度:
    • 熱門焦點

    最新推薦

    猜你喜歡

    熱門推薦

    專題
    Top
    主站蜘蛛池模板: 久久影院综合精品| 国产精品美女一区二区视频| 久久99精品久久久久久久久久| 国产成人无码精品久久久免费| 亚洲国产精品无码久久久不卡 | 亚洲午夜精品久久久久久app| 亚洲第一精品在线视频| 久久99精品久久久久子伦| 好湿好大硬得深一点动态图91精品福利一区二区 | 国产探花在线精品一区二区| 中文字幕无码精品亚洲资源网久久| 亚洲精品在线观看视频| 国产成人精品一区二区三区免费| 亚洲中文久久精品无码ww16| 欧美日韩精品在线观看| 国产亚洲精品线观看动态图| 97精品人妻一区二区三区香蕉| www.亚洲精品.com| 99热国内精品| 精品免费视在线观看| 国产高清在线精品一区| 99re这里只有精品国产精品| 国产精品9999久久久久| 久久精品无码专区免费东京热 | 国内精品手机在线观看视频| 国产精品日本一区二区在线播放| 无码欧精品亚洲日韩一区| 一本色道久久88—综合亚洲精品 | 久久99国产综合精品| 国内揄拍高清国内精品对白| 精品成在人线AV无码免费看| 国产午夜精品久久久久免费视| 久久久久久九九99精品| 久久精品国产亚洲AV高清热| 精品国产三级a在线观看| 国产精品特级毛片一区二区三区| 国产成人精品无码免费看| 2020亚洲男人天堂精品| 久久精品国产亚洲沈樵| 91精品国产高清久久久久久91| 国产高清精品在线|