<gh_stars>0
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'calc.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_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(379, 600)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(10, 10, 361, 91))
        font = QtGui.QFont()
        font.setPointSize(18)
        self.label.setFont(font)
        self.label.setFrameShape(QtWidgets.QFrame.Box)
        self.label.setFrameShadow(QtWidgets.QFrame.Raised)
        self.label.setLineWidth(1)
        self.label.setText("")
        self.label.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.label.setObjectName("label")
        self.per_Button = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.press_it("%"))
        self.per_Button.setGeometry(QtCore.QRect(10, 110, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.per_Button.setFont(font)
        self.per_Button.setObjectName("per_Button")
        self.c_button = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.press_it("C"))
        self.c_button.setGeometry(QtCore.QRect(100, 110, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.c_button.setFont(font)
        self.c_button.setObjectName("c_button")
        self.greater_button = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.remove_char())
        self.greater_button.setGeometry(QtCore.QRect(190, 110, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.greater_button.setFont(font)
        self.greater_button.setObjectName("greater_button")
        self.div_button = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.press_it("/"))
        self.div_button.setGeometry(QtCore.QRect(280, 110, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.div_button.setFont(font)
        self.div_button.setObjectName("div_button")
        self.nine = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.press_it("9"))
        self.nine.setGeometry(QtCore.QRect(190, 200, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.nine.setFont(font)
        self.nine.setObjectName("nine")
        self.one = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.press_it("1"))
        self.one.setGeometry(QtCore.QRect(10, 380, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.one.setFont(font)
        self.one.setObjectName("one")
        self.four = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.press_it("4"))
        self.four.setGeometry(QtCore.QRect(10, 290, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.four.setFont(font)
        self.four.setObjectName("four")
        self.seven = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.press_it("7"))
        self.seven.setGeometry(QtCore.QRect(10, 200, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.seven.setFont(font)
        self.seven.setObjectName("seven")
        self.sub_button = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.press_it("-"))
        self.sub_button.setGeometry(QtCore.QRect(280, 290, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.sub_button.setFont(font)
        self.sub_button.setObjectName("sub_button")
        self.six = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.press_it("6"))
        self.six.setGeometry(QtCore.QRect(190, 290, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.six.setFont(font)
        self.six.setObjectName("six")
        self.five = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.press_it("5"))
        self.five.setGeometry(QtCore.QRect(100, 290, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.five.setFont(font)
        self.five.setObjectName("five")
        self.mul_button = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.press_it("*"))
        self.mul_button.setGeometry(QtCore.QRect(280, 200, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.mul_button.setFont(font)
        self.mul_button.setObjectName("mul_button")
        self.eight = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.press_it("8"))
        self.eight.setGeometry(QtCore.QRect(100, 200, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.eight.setFont(font)
        self.eight.setObjectName("eight")
        self.dot_button = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.dot_it() )
        self.dot_button.setGeometry(QtCore.QRect(190, 470, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.dot_button.setFont(font)
        self.dot_button.setObjectName("dot_button")
        self.add_button = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.press_it("+"))
        self.add_button.setGeometry(QtCore.QRect(280, 380, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.add_button.setFont(font)
        self.add_button.setObjectName("add_button")
        self.zero = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.press_it("0"))
        self.zero.setGeometry(QtCore.QRect(100, 470, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.zero.setFont(font)
        self.zero.setObjectName("zero")
        self.mix_button = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.mix())
        self.mix_button.setGeometry(QtCore.QRect(10, 470, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.mix_button.setFont(font)
        self.mix_button.setObjectName("mix_button")
        self.three = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.press_it("3"))
        self.three.setGeometry(QtCore.QRect(190, 380, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.three.setFont(font)
        self.three.setObjectName("three")
        self.two = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.press_it("2"))
        self.two.setGeometry(QtCore.QRect(100, 380, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.two.setFont(font)
        self.two.setObjectName("two")
        self.equal_button = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.math_it())
        self.equal_button.setGeometry(QtCore.QRect(280, 470, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.equal_button.setFont(font)
        self.equal_button.setObjectName("equal_button")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 379, 26))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
    def press_it(self,pressed):
        if pressed == "C":
            self.label.setText("0")
        else:
        #check if starts with zero and then delete the zero
            if self.label.text()=="0":
                self.label.setText("")

            self.label.setText(f'{self.label.text()}{pressed}')
            #self.label.setText(pressed)
    def dot_it(self):
        screen = self.label.text()
        if screen[-1]==".":
            pass
        else:
            self.label.setText(f'{screen}.')

    def remove_char(self):
        screen = self.label.text()
        screen = screen[:-1]  #remove last string
        self.label.setText(screen)

    def mix(self):
        screen = self.label.text()
        if(screen[0] == "-"):
            self.label.setText(screen.replace("-",""))
        else:
            self.label.setText(f'-{screen}')
    def math_it(self):
        screen= self.label.text()
        try:
            answer = eval(screen)
            self.label.setText(str(answer))
        except:
            self.label.setText("ERROR")
        





        


        



    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "Calculator"))
        self.per_Button.setText(_translate("MainWindow", "%"))
        self.c_button.setText(_translate("MainWindow", "C"))
        self.greater_button.setText(_translate("MainWindow", "<<"))
        self.div_button.setText(_translate("MainWindow", "/"))
        self.nine.setText(_translate("MainWindow", "9"))
        self.one.setText(_translate("MainWindow", "1"))
        self.four.setText(_translate("MainWindow", "4"))
        self.seven.setText(_translate("MainWindow", "7"))
        self.sub_button.setText(_translate("MainWindow", "-"))
        self.six.setText(_translate("MainWindow", "6"))
        self.five.setText(_translate("MainWindow", "5"))
        self.mul_button.setText(_translate("MainWindow", "*"))
        self.eight.setText(_translate("MainWindow", "8"))
        self.dot_button.setText(_translate("MainWindow", "."))
        self.add_button.setText(_translate("MainWindow", "+"))
        self.zero.setText(_translate("MainWindow", "0"))
        self.mix_button.setText(_translate("MainWindow", "+/-"))
        self.three.setText(_translate("MainWindow", "3"))
        self.two.setText(_translate("MainWindow", "2"))
        self.equal_button.setText(_translate("MainWindow", "="))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())

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

# Form implementation generated from reading ui file 'calc.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_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(379, 600)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(10, 10, 361, 91))
        font = QtGui.QFont()
        font.setPointSize(18)
        self.label.setFont(font)
        self.label.setFrameShape(QtWidgets.QFrame.Box)
        self.label.setFrameShadow(QtWidgets.QFrame.Raised)
        self.label.setLineWidth(1)
        self.label.setText("")
        self.label.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.label.setObjectName("label")
        self.per_Button = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.press_it("%"))
        self.per_Button.setGeometry(QtCore.QRect(10, 110, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.per_Button.setFont(font)
        self.per_Button.setObjectName("per_Button")
        self.c_button = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.press_it("C"))
        self.c_button.setGeometry(QtCore.QRect(100, 110, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.c_button.setFont(font)
        self.c_button.setObjectName("c_button")
        self.greater_button = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.remove_char())
        self.greater_button.setGeometry(QtCore.QRect(190, 110, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.greater_button.setFont(font)
        self.greater_button.setObjectName("greater_button")
        self.div_button = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.press_it("/"))
        self.div_button.setGeometry(QtCore.QRect(280, 110, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.div_button.setFont(font)
        self.div_button.setObjectName("div_button")
        self.nine = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.press_it("9"))
        self.nine.setGeometry(QtCore.QRect(190, 200, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.nine.setFont(font)
        self.nine.setObjectName("nine")
        self.one = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.press_it("1"))
        self.one.setGeometry(QtCore.QRect(10, 380, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.one.setFont(font)
        self.one.setObjectName("one")
        self.four = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.press_it("4"))
        self.four.setGeometry(QtCore.QRect(10, 290, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.four.setFont(font)
        self.four.setObjectName("four")
        self.seven = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.press_it("7"))
        self.seven.setGeometry(QtCore.QRect(10, 200, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.seven.setFont(font)
        self.seven.setObjectName("seven")
        self.sub_button = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.press_it("-"))
        self.sub_button.setGeometry(QtCore.QRect(280, 290, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.sub_button.setFont(font)
        self.sub_button.setObjectName("sub_button")
        self.six = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.press_it("6"))
        self.six.setGeometry(QtCore.QRect(190, 290, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.six.setFont(font)
        self.six.setObjectName("six")
        self.five = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.press_it("5"))
        self.five.setGeometry(QtCore.QRect(100, 290, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.five.setFont(font)
        self.five.setObjectName("five")
        self.mul_button = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.press_it("*"))
        self.mul_button.setGeometry(QtCore.QRect(280, 200, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.mul_button.setFont(font)
        self.mul_button.setObjectName("mul_button")
        self.eight = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.press_it("8"))
        self.eight.setGeometry(QtCore.QRect(100, 200, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.eight.setFont(font)
        self.eight.setObjectName("eight")
        self.dot_button = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.dot_it() )
        self.dot_button.setGeometry(QtCore.QRect(190, 470, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.dot_button.setFont(font)
        self.dot_button.setObjectName("dot_button")
        self.add_button = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.press_it("+"))
        self.add_button.setGeometry(QtCore.QRect(280, 380, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.add_button.setFont(font)
        self.add_button.setObjectName("add_button")
        self.zero = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.press_it("0"))
        self.zero.setGeometry(QtCore.QRect(100, 470, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.zero.setFont(font)
        self.zero.setObjectName("zero")
        self.mix_button = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.mix())
        self.mix_button.setGeometry(QtCore.QRect(10, 470, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.mix_button.setFont(font)
        self.mix_button.setObjectName("mix_button")
        self.three = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.press_it("3"))
        self.three.setGeometry(QtCore.QRect(190, 380, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.three.setFont(font)
        self.three.setObjectName("three")
        self.two = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.press_it("2"))
        self.two.setGeometry(QtCore.QRect(100, 380, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.two.setFont(font)
        self.two.setObjectName("two")
        self.equal_button = QtWidgets.QPushButton(self.centralwidget,clicked =lambda : self.math_it())
        self.equal_button.setGeometry(QtCore.QRect(280, 470, 75, 75))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.equal_button.setFont(font)
        self.equal_button.setObjectName("equal_button")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 379, 26))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
    def press_it(self,pressed):
        if pressed == "C":
            self.label.setText("0")
        else:
        #check if starts with zero and then delete the zero
            if self.label.text()=="0":
                self.label.setText("")

            self.label.setText(f'{self.label.text()}{pressed}')
            #self.label.setText(pressed)
    def dot_it(self):
        screen = self.label.text()
        if screen[-1]==".":
            pass
        else:
            self.label.setText(f'{screen}.')

    def remove_char(self):
        screen = self.label.text()
        screen = screen[:-1]  #remove last string
        self.label.setText(screen)

    def mix(self):
        screen = self.label.text()
        if(screen[0] == "-"):
            self.label.setText(screen.replace("-",""))
        else:
            self.label.setText(f'-{screen}')
    def math_it(self):
        screen= self.label.text()
        try:
            answer = eval(screen)
            self.label.setText(str(answer))
        except:
            self.label.setText("ERROR")
        





        


        



    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "Calculator"))
        self.per_Button.setText(_translate("MainWindow", "%"))
        self.c_button.setText(_translate("MainWindow", "C"))
        self.greater_button.setText(_translate("MainWindow", "<<"))
        self.div_button.setText(_translate("MainWindow", "/"))
        self.nine.setText(_translate("MainWindow", "9"))
        self.one.setText(_translate("MainWindow", "1"))
        self.four.setText(_translate("MainWindow", "4"))
        self.seven.setText(_translate("MainWindow", "7"))
        self.sub_button.setText(_translate("MainWindow", "-"))
        self.six.setText(_translate("MainWindow", "6"))
        self.five.setText(_translate("MainWindow", "5"))
        self.mul_button.setText(_translate("MainWindow", "*"))
        self.eight.setText(_translate("MainWindow", "8"))
        self.dot_button.setText(_translate("MainWindow", "."))
        self.add_button.setText(_translate("MainWindow", "+"))
        self.zero.setText(_translate("MainWindow", "0"))
        self.mix_button.setText(_translate("MainWindow", "+/-"))
        self.three.setText(_translate("MainWindow", "3"))
        self.two.setText(_translate("MainWindow", "2"))
        self.equal_button.setText(_translate("MainWindow", "="))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())
# -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'calc.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. #check if starts with zero and then delete the zero #self.label.setText(pressed) #remove last string