При нажатии на любую кнопку ничего не происходит
Помогите решить проблему пожалуйста, при нажатии на любую из кнопок и даже на кнопку "debug"
ничего не происходит?
Ничего важного я не менял с прошлого работающего кода, однако всё равно ничего не происходит
from PyQt5 import QtCore, QtGui, QtWidgets
from decimal import *
from math import *
class Ui_Calculator(object):
def setupUi(self, Calculator):
Calculator.setObjectName("Calculator")
Calculator.resize(322, 386)
Calculator.setStyleSheet("background-color: rgb(0, 0, 0);")
self.centralwidget = QtWidgets.QWidget(Calculator)
self.centralwidget.setObjectName("centralwidget")
self.display = QtWidgets.QLabel(self.centralwidget)
self.display.setGeometry(QtCore.QRect(-1, 0, 322, 61))
self.display.setStyleSheet("font: 25pt \"Nirmala UI\";\n"
"color: rgb(255, 255, 255);")
self.display.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.display.setObjectName("display")
self.btn_c = QtWidgets.QPushButton(self.centralwidget)
self.btn_c.setGeometry(QtCore.QRect(0, 126, 65, 65))
self.btn_c.setStyleSheet("font: 18pt \"Nirmala UI\";\n"
"color: rgb(255, 109, 25);\n"
"background-color: rgb(0, 0, 0);")
self.btn_c.setObjectName("btn_c")
self.btn_dot = QtWidgets.QPushButton(self.centralwidget)
self.btn_dot.setGeometry(QtCore.QRect(194, 64, 65, 65))
self.btn_dot.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 109, 25);\n"
"background-color: rgb(0, 0, 0);")
self.btn_dot.setObjectName("btn_dot")
self.btn_proc = QtWidgets.QPushButton(self.centralwidget)
self.btn_proc.setGeometry(QtCore.QRect(65, 322, 65, 65))
self.btn_proc.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 255, 255);\n"
"background-color: rgb(255, 109, 25);")
self.btn_proc.setObjectName("btn_proc")
self.btn_div = QtWidgets.QPushButton(self.centralwidget)
self.btn_div.setGeometry(QtCore.QRect(258, 64, 65, 65))
self.btn_div.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 109, 25);\n"
"background-color: rgb(0, 0, 0);")
self.btn_div.setObjectName("btn_div")
self.btn_7 = QtWidgets.QPushButton(self.centralwidget)
self.btn_7.setGeometry(QtCore.QRect(66, 128, 65, 65))
self.btn_7.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 255, 255);\n"
"background-color: rgb(0, 0, 0);")
self.btn_7.setObjectName("btn_7")
self.btn_8 = QtWidgets.QPushButton(self.centralwidget)
self.btn_8.setGeometry(QtCore.QRect(130, 128, 65, 65))
self.btn_8.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 255, 255);\n"
"background-color: rgb(0, 0, 0);")
self.btn_8.setObjectName("btn_8")
self.btn_9 = QtWidgets.QPushButton(self.centralwidget)
self.btn_9.setGeometry(QtCore.QRect(194, 128, 65, 65))
self.btn_9.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 255, 255);\n"
"background-color: rgb(0, 0, 0);")
self.btn_9.setObjectName("btn_9")
self.btn_mult = QtWidgets.QPushButton(self.centralwidget)
self.btn_mult.setGeometry(QtCore.QRect(258, 128, 65, 65))
self.btn_mult.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 109, 25);\n"
"background-color: rgb(0, 0, 0);")
self.btn_mult.setObjectName("btn_mult")
self.btn_4 = QtWidgets.QPushButton(self.centralwidget)
self.btn_4.setGeometry(QtCore.QRect(66, 192, 65, 65))
self.btn_4.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 255, 255);\n"
"background-color: rgb(0, 0, 0);")
self.btn_4.setObjectName("btn_4")
self.btn_plus = QtWidgets.QPushButton(self.centralwidget)
self.btn_plus.setGeometry(QtCore.QRect(258, 256, 65, 65))
self.btn_plus.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 109, 25);\n"
"background-color: rgb(0, 0, 0);")
self.btn_plus.setObjectName("btn_plus")
self.btn_5 = QtWidgets.QPushButton(self.centralwidget)
self.btn_5.setGeometry(QtCore.QRect(130, 192, 65, 65))
self.btn_5.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 255, 255);\n"
"background-color: rgb(0, 0, 0);")
self.btn_5.setObjectName("btn_5")
self.btn_6 = QtWidgets.QPushButton(self.centralwidget)
self.btn_6.setGeometry(QtCore.QRect(194, 192, 65, 65))
self.btn_6.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 255, 255);\n"
"background-color: rgb(0, 0, 0);")
self.btn_6.setObjectName("btn_6")
self.btn_1 = QtWidgets.QPushButton(self.centralwidget)
self.btn_1.setGeometry(QtCore.QRect(66, 256, 65, 65))
self.btn_1.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"gridline-color: rgb(255, 255, 255);\n"
"color: rgb(255, 255, 255);")
self.btn_1.setObjectName("btn_1")
self.btn_3 = QtWidgets.QPushButton(self.centralwidget)
self.btn_3.setGeometry(QtCore.QRect(194, 256, 65, 65))
self.btn_3.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 255, 255);\n"
"background-color: rgb(0, 0, 0);")
self.btn_3.setObjectName("btn_3")
self.btn_2 = QtWidgets.QPushButton(self.centralwidget)
self.btn_2.setGeometry(QtCore.QRect(130, 256, 65, 65))
self.btn_2.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 255, 255);\n"
"background-color: rgb(0, 0, 0);")
self.btn_2.setObjectName("btn_2")
self.btn_min = QtWidgets.QPushButton(self.centralwidget)
self.btn_min.setGeometry(QtCore.QRect(258, 192, 65, 65))
self.btn_min.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 109, 25);\n"
"background-color: rgb(0, 0, 0);")
self.btn_min.setObjectName("btn_min")
self.btn_zero = QtWidgets.QPushButton(self.centralwidget)
self.btn_zero.setGeometry(QtCore.QRect(130, 320, 65, 65))
self.btn_zero.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 255, 255);\n"
"background-color: rgb(0, 0, 0);")
self.btn_zero.setObjectName("btn_zero")
self.btn_eq = QtWidgets.QPushButton(self.centralwidget)
self.btn_eq.setGeometry(QtCore.QRect(258, 322, 65, 65))
self.btn_eq.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 255, 255);\n"
"background-color: rgb(255, 109, 25);")
self.btn_eq.setObjectName("btn_eq")
self.btn_debug = QtWidgets.QPushButton(self.centralwidget)
self.btn_debug.setGeometry(QtCore.QRect(193, 322, 65, 65))
font = QtGui.QFont()
font.setFamily("Nirmala UI")
font.setPointSize(14)
font.setBold(False)
font.setItalic(False)
font.setWeight(50)
self.btn_debug.setFont(font)
self.btn_debug.setStyleSheet("font:\"Nirmala UI\";\n"
"color: rgb(255, 255, 255);\n"
"background-color: rgb(255, 109, 25);")
self.btn_debug.setObjectName("btn_debug")
self.btn_basp = QtWidgets.QPushButton(self.centralwidget)
self.btn_basp.setGeometry(QtCore.QRect(0, 64, 65, 65))
self.btn_basp.setStyleSheet("font: 18pt \"Nirmala UI\";\n"
"color: rgb(255, 109, 25);\n"
"background-color: rgb(0, 0, 0);")
self.btn_basp.setObjectName("btn_basp")
self.btn_pi = QtWidgets.QPushButton(self.centralwidget)
self.btn_pi.setGeometry(QtCore.QRect(0, 322, 65, 65))
self.btn_pi.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 255, 255);\n"
"background-color: rgb(255, 109, 25);")
self.btn_pi.setObjectName("btn_pi")
self.btn_deg = QtWidgets.QPushButton(self.centralwidget)
self.btn_deg.setGeometry(QtCore.QRect(0, 257, 65, 65))
self.btn_deg.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 255, 255);\n"
"background-color: rgb(255, 109, 25);")
self.btn_deg.setObjectName("btn_deg")
self.btn_rox = QtWidgets.QPushButton(self.centralwidget)
self.btn_rox.setGeometry(QtCore.QRect(0, 192, 65, 65))
self.btn_rox.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 255, 255);\n"
"background-color: rgb(255, 109, 25);")
self.btn_rox.setObjectName("btn_rox")
self.btn_bl = QtWidgets.QPushButton(self.centralwidget)
self.btn_bl.setGeometry(QtCore.QRect(66, 64, 65, 65))
self.btn_bl.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 109, 25);\n"
"background-color: rgb(0, 0, 0);")
self.btn_bl.setObjectName("btn_bl")
self.btn_br = QtWidgets.QPushButton(self.centralwidget)
self.btn_br.setGeometry(QtCore.QRect(130, 64, 65, 65))
self.btn_br.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 109, 25);\n"
"background-color: rgb(0, 0, 0);")
self.btn_br.setObjectName("btn_br")
self.btn_eq.raise_()
self.display.raise_()
self.btn_c.raise_()
self.btn_dot.raise_()
self.btn_proc.raise_()
self.btn_div.raise_()
self.btn_7.raise_()
self.btn_8.raise_()
self.btn_9.raise_()
self.btn_mult.raise_()
self.btn_4.raise_()
self.btn_plus.raise_()
self.btn_5.raise_()
self.btn_6.raise_()
self.btn_1.raise_()
self.btn_3.raise_()
self.btn_2.raise_()
self.btn_min.raise_()
self.btn_zero.raise_()
self.btn_debug.raise_()
self.btn_basp.raise_()
self.btn_pi.raise_()
self.btn_deg.raise_()
self.btn_rox.raise_()
self.btn_bl.raise_()
self.btn_br.raise_()
Calculator.setCentralWidget(self.centralwidget)
self.retranslateUi(Calculator)
QtCore.QMetaObject.connectSlotsByName(Calculator)
def retranslateUi(self, Calculator):
_translate = QtCore.QCoreApplication.translate
Calculator.setWindowTitle(_translate("Calculator", "Calculator"))
self.display.setText(_translate("Calculator", "0"))
self.btn_c.setText(_translate("Calculator", "C"))
self.btn_dot.setText(_translate("Calculator", ","))
self.btn_proc.setText(_translate("Calculator", "%"))
self.btn_div.setText(_translate("Calculator", "÷"))
self.btn_7.setText(_translate("Calculator", "7"))
self.btn_8.setText(_translate("Calculator", "8"))
self.btn_9.setText(_translate("Calculator", "9"))
self.btn_mult.setText(_translate("Calculator", "×"))
self.btn_4.setText(_translate("Calculator", "4"))
self.btn_plus.setText(_translate("Calculator", "+"))
self.btn_5.setText(_translate("Calculator", "5"))
self.btn_6.setText(_translate("Calculator", "6"))
self.btn_1.setText(_translate("Calculator", "1"))
self.btn_3.setText(_translate("Calculator", "3"))
self.btn_2.setText(_translate("Calculator", "2"))
self.btn_min.setText(_translate("Calculator", "−"))
self.btn_zero.setText(_translate("Calculator", "0"))
self.btn_eq.setText(_translate("Calculator", "="))
self.btn_debug.setText(_translate("Calculator", "DEBUG"))
self.btn_basp.setText(_translate("Calculator", "⌫"))
self.btn_pi.setText(_translate("Calculator", "?"))
self.btn_deg.setText(_translate("Calculator", "x²"))
self.btn_rox.setText(_translate("Calculator", "√"))
self.btn_bl.setText(_translate("Calculator", "("))
self.btn_br.setText(_translate("Calculator", ")"))
class MainWindow(QtWidgets.QMainWindow, Ui_Calculator):
def __init__(self):
super().__init__()
self.setupUi(self)
self.action_plus = 0
self.action_min = 0
self.action_mult = 0
self.action_div = 0
self.action_dot = 0
self.btn_debug.clicked.connect(self.debug)
self.btn_zero.clicked.connect(lambda: self.num_handler("0", "0"))
self.btn_1.clicked.connect(lambda: self.num_handler("1", "1"))
self.btn_2.clicked.connect(lambda: self.num_handler("2", "2"))
self.btn_3.clicked.connect(lambda: self.num_handler("3", "3"))
self.btn_4.clicked.connect(lambda: self.num_handler("4", "4"))
self.btn_5.clicked.connect(lambda: self.num_handler("5", "5"))
self.btn_6.clicked.connect(lambda: self.num_handler("6", "6"))
self.btn_7.clicked.connect(lambda: self.num_handler("7", "7"))
self.btn_8.clicked.connect(lambda: self.num_handler("8", "8"))
self.btn_9.clicked.connect(lambda: self.num_handler("9", "9"))
self.btn_bl.clicked.connect(lambda: self.num_handler("(", "("))
self.btn_br.clicked.connect(lambda: self.num_handler(")", ")"))
self.btn_plus.clicked.connect(lambda: self.num_handler("+", "+"))
self.btn_min.clicked.connect(lambda: self.num_handler("−", "-"))
self.btn_mult.clicked.connect(lambda: self.num_handler("×", "*"))
self.btn_div.clicked.connect(lambda: self.num_handler("÷", "/"))
self.btn_dot.clicked.connect(lambda: self.num_handler(",", "."))
self.btn_del.clicked.connect(self.delete)
self.btn_proc.clicked.connect(self.procent)
self.btn_eq.clicked.connect(self.results)
self.input_symbols = ""
self.action = 0
def num_handler(self, num1, num2):
self.input_symbols = str(self.input_symbols)
num1 = str(num1)
num2 = str(num2)
print(f"Натиснуто: {num1}")
if self.action == 0:
self.action = 1
self.display.setText(num1)
self.input_symbols = num2
else:
self.display.setText(self.display.text()+ num1)
self.input_symbols =+ num2
"""def num_in_input_symbols(self, symbol):
self.input_symbols = str(self.input_symbols)
symbol = str(symbol)
if self.action == 0:
self.input_symbols = ""
self.input_symbols = symbol
self.action = 1
else:
self.input_symbols = self.input_symbols + symbol
print(f'Натиснуто: "{symbol}" ')
def visual(self, symbol):
print(symbol)
if self.action == 0:
self.display.setText(symbol)
self.action = 1
else:
self.display.setText(self.display.text()+ symbol)"""
def delete(self):
try:
print(f'Змінна input_symbols = {self.input_symbols}')
self.display.setText("0")
self.action = 0
print(f"Pressed? {self.action}")
self.input_symbols = ""
except Exception as e:
print("Error:", e)
def rounding(self, number):
try:
if number % 1 == 0:
return int(number)
else:
return round(number, 8)
except Exception as e:
print("Error:", e)
"""def rox(self, number):
pass
def deg(self, number):
pass
def basp(self, num):
pass
def pi(self):
pass"""
def procent(self):
try:
num = self.display.text()
if num.find("+") == -1 and num.find("-") == -1 and num.find("*") == -1 and num.find("/") == -1:
p1 = float(num)
p2 = p1 / 100
self.input_symbols = p2
p2=str(p2)
p2 = p2.replace(".", ",")
self.display.setText(p2)
else:
self.action = 0
except Exception as e:
print("Error:", e)
def results(self):
try:
r1 = eval(self.input_symbols)
r2 = self.rounding(r1)
r2 = str(r2)
r2 = r2.replace(".", ",")
self.display.setText(r2)
self.action = 0
except Exception as e:
print("Error:", e)
def debug(self):
print(f'''×--------------------------------------------×
⦁ Що відображено? {self.display.text()}
⦁ Чи є щось в input_symbols? {self.input_symbols}
⦁ Чи була дія? {self.action}
×--------------------------------------------×''')
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Calculator = QtWidgets.QMainWindow()
ui = Ui_Calculator()
ui.setupUi(Calculator)
Calculator.show()
sys.exit(app.exec_())
Ответы (1 шт):
Автор решения: S. Nick
→ Ссылка
Я кое-что исправил и написал вам в коде, но вам еще надо много трудиться. Удачи вам.
from decimal import *
from math import *
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Calculator(object):
def setupUi(self, Calculator):
Calculator.setObjectName("Calculator")
Calculator.resize(322, 386)
Calculator.setStyleSheet("background-color: rgb(0, 0, 0);")
self.centralwidget = QtWidgets.QWidget(Calculator)
self.centralwidget.setObjectName("centralwidget")
self.display = QtWidgets.QLabel(self.centralwidget)
self.display.setGeometry(QtCore.QRect(-1, 0, 322, 61))
self.display.setStyleSheet("font: 25pt \"Nirmala UI\";\n"
"color: rgb(255, 255, 255);")
self.display.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.display.setObjectName("display")
self.btn_c = QtWidgets.QPushButton(self.centralwidget)
self.btn_c.setGeometry(QtCore.QRect(0, 126, 65, 65))
self.btn_c.setStyleSheet("font: 18pt \"Nirmala UI\";\n"
"color: rgb(255, 109, 25);\n"
"background-color: rgb(0, 0, 0);")
self.btn_c.setObjectName("btn_c")
self.btn_dot = QtWidgets.QPushButton(self.centralwidget)
self.btn_dot.setGeometry(QtCore.QRect(194, 64, 65, 65))
self.btn_dot.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 109, 25);\n"
"background-color: rgb(0, 0, 0);")
self.btn_dot.setObjectName("btn_dot")
self.btn_proc = QtWidgets.QPushButton(self.centralwidget)
self.btn_proc.setGeometry(QtCore.QRect(65, 322, 65, 65))
self.btn_proc.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 255, 255);\n"
"background-color: rgb(255, 109, 25);")
self.btn_proc.setObjectName("btn_proc")
self.btn_div = QtWidgets.QPushButton(self.centralwidget)
self.btn_div.setGeometry(QtCore.QRect(258, 64, 65, 65))
self.btn_div.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 109, 25);\n"
"background-color: rgb(0, 0, 0);")
self.btn_div.setObjectName("btn_div")
self.btn_7 = QtWidgets.QPushButton(self.centralwidget)
self.btn_7.setGeometry(QtCore.QRect(66, 128, 65, 65))
self.btn_7.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 255, 255);\n"
"background-color: rgb(0, 0, 0);")
self.btn_7.setObjectName("btn_7")
self.btn_8 = QtWidgets.QPushButton(self.centralwidget)
self.btn_8.setGeometry(QtCore.QRect(130, 128, 65, 65))
self.btn_8.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 255, 255);\n"
"background-color: rgb(0, 0, 0);")
self.btn_8.setObjectName("btn_8")
self.btn_9 = QtWidgets.QPushButton(self.centralwidget)
self.btn_9.setGeometry(QtCore.QRect(194, 128, 65, 65))
self.btn_9.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 255, 255);\n"
"background-color: rgb(0, 0, 0);")
self.btn_9.setObjectName("btn_9")
self.btn_mult = QtWidgets.QPushButton(self.centralwidget)
self.btn_mult.setGeometry(QtCore.QRect(258, 128, 65, 65))
self.btn_mult.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 109, 25);\n"
"background-color: rgb(0, 0, 0);")
self.btn_mult.setObjectName("btn_mult")
self.btn_4 = QtWidgets.QPushButton(self.centralwidget)
self.btn_4.setGeometry(QtCore.QRect(66, 192, 65, 65))
self.btn_4.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 255, 255);\n"
"background-color: rgb(0, 0, 0);")
self.btn_4.setObjectName("btn_4")
self.btn_plus = QtWidgets.QPushButton(self.centralwidget)
self.btn_plus.setGeometry(QtCore.QRect(258, 256, 65, 65))
self.btn_plus.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 109, 25);\n"
"background-color: rgb(0, 0, 0);")
self.btn_plus.setObjectName("btn_plus")
self.btn_5 = QtWidgets.QPushButton(self.centralwidget)
self.btn_5.setGeometry(QtCore.QRect(130, 192, 65, 65))
self.btn_5.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 255, 255);\n"
"background-color: rgb(0, 0, 0);")
self.btn_5.setObjectName("btn_5")
self.btn_6 = QtWidgets.QPushButton(self.centralwidget)
self.btn_6.setGeometry(QtCore.QRect(194, 192, 65, 65))
self.btn_6.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 255, 255);\n"
"background-color: rgb(0, 0, 0);")
self.btn_6.setObjectName("btn_6")
self.btn_1 = QtWidgets.QPushButton(self.centralwidget)
self.btn_1.setGeometry(QtCore.QRect(66, 256, 65, 65))
self.btn_1.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"gridline-color: rgb(255, 255, 255);\n"
"color: rgb(255, 255, 255);")
self.btn_1.setObjectName("btn_1")
self.btn_3 = QtWidgets.QPushButton(self.centralwidget)
self.btn_3.setGeometry(QtCore.QRect(194, 256, 65, 65))
self.btn_3.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 255, 255);\n"
"background-color: rgb(0, 0, 0);")
self.btn_3.setObjectName("btn_3")
self.btn_2 = QtWidgets.QPushButton(self.centralwidget)
self.btn_2.setGeometry(QtCore.QRect(130, 256, 65, 65))
self.btn_2.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 255, 255);\n"
"background-color: rgb(0, 0, 0);")
self.btn_2.setObjectName("btn_2")
self.btn_min = QtWidgets.QPushButton(self.centralwidget)
self.btn_min.setGeometry(QtCore.QRect(258, 192, 65, 65))
self.btn_min.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 109, 25);\n"
"background-color: rgb(0, 0, 0);")
self.btn_min.setObjectName("btn_min")
self.btn_zero = QtWidgets.QPushButton(self.centralwidget)
self.btn_zero.setGeometry(QtCore.QRect(130, 320, 65, 65))
self.btn_zero.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 255, 255);\n"
"background-color: rgb(0, 0, 0);")
self.btn_zero.setObjectName("btn_zero")
self.btn_eq = QtWidgets.QPushButton(self.centralwidget)
self.btn_eq.setGeometry(QtCore.QRect(258, 322, 65, 65))
self.btn_eq.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 255, 255);\n"
"background-color: rgb(255, 109, 25);")
self.btn_eq.setObjectName("btn_eq")
self.btn_debug = QtWidgets.QPushButton(self.centralwidget)
self.btn_debug.setGeometry(QtCore.QRect(193, 322, 65, 65))
font = QtGui.QFont()
font.setFamily("Nirmala UI")
font.setPointSize(14)
font.setBold(False)
font.setItalic(False)
font.setWeight(50)
self.btn_debug.setFont(font)
self.btn_debug.setStyleSheet("font:\"Nirmala UI\";\n"
"color: rgb(255, 255, 255);\n"
"background-color: rgb(255, 109, 25);")
self.btn_debug.setObjectName("btn_debug")
self.btn_basp = QtWidgets.QPushButton(self.centralwidget)
self.btn_basp.setGeometry(QtCore.QRect(0, 64, 65, 65))
self.btn_basp.setStyleSheet("font: 18pt \"Nirmala UI\";\n"
"color: rgb(255, 109, 25);\n"
"background-color: rgb(0, 0, 0);")
self.btn_basp.setObjectName("btn_basp")
self.btn_pi = QtWidgets.QPushButton(self.centralwidget)
self.btn_pi.setGeometry(QtCore.QRect(0, 322, 65, 65))
self.btn_pi.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 255, 255);\n"
"background-color: rgb(255, 109, 25);")
self.btn_pi.setObjectName("btn_pi")
self.btn_deg = QtWidgets.QPushButton(self.centralwidget)
self.btn_deg.setGeometry(QtCore.QRect(0, 257, 65, 65))
self.btn_deg.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 255, 255);\n"
"background-color: rgb(255, 109, 25);")
self.btn_deg.setObjectName("btn_deg")
self.btn_rox = QtWidgets.QPushButton(self.centralwidget)
self.btn_rox.setGeometry(QtCore.QRect(0, 192, 65, 65))
self.btn_rox.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 255, 255);\n"
"background-color: rgb(255, 109, 25);")
self.btn_rox.setObjectName("btn_rox")
self.btn_bl = QtWidgets.QPushButton(self.centralwidget)
self.btn_bl.setGeometry(QtCore.QRect(66, 64, 65, 65))
self.btn_bl.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 109, 25);\n"
"background-color: rgb(0, 0, 0);")
self.btn_bl.setObjectName("btn_bl")
self.btn_br = QtWidgets.QPushButton(self.centralwidget)
self.btn_br.setGeometry(QtCore.QRect(130, 64, 65, 65))
self.btn_br.setStyleSheet("font: 22pt \"Nirmala UI\";\n"
"color: rgb(255, 109, 25);\n"
"background-color: rgb(0, 0, 0);")
self.btn_br.setObjectName("btn_br")
self.btn_eq.raise_()
self.display.raise_()
self.btn_c.raise_()
self.btn_dot.raise_()
self.btn_proc.raise_()
self.btn_div.raise_()
self.btn_7.raise_()
self.btn_8.raise_()
self.btn_9.raise_()
self.btn_mult.raise_()
self.btn_4.raise_()
self.btn_plus.raise_()
self.btn_5.raise_()
self.btn_6.raise_()
self.btn_1.raise_()
self.btn_3.raise_()
self.btn_2.raise_()
self.btn_min.raise_()
self.btn_zero.raise_()
self.btn_debug.raise_()
self.btn_basp.raise_()
self.btn_pi.raise_()
self.btn_deg.raise_()
self.btn_rox.raise_()
self.btn_bl.raise_()
self.btn_br.raise_()
Calculator.setCentralWidget(self.centralwidget)
self.retranslateUi(Calculator)
QtCore.QMetaObject.connectSlotsByName(Calculator)
def retranslateUi(self, Calculator):
_translate = QtCore.QCoreApplication.translate
Calculator.setWindowTitle(_translate("Calculator", "Calculator"))
self.display.setText(_translate("Calculator", "0"))
self.btn_c.setText(_translate("Calculator", "C"))
self.btn_dot.setText(_translate("Calculator", ","))
self.btn_proc.setText(_translate("Calculator", "%"))
self.btn_div.setText(_translate("Calculator", "÷"))
self.btn_7.setText(_translate("Calculator", "7"))
self.btn_8.setText(_translate("Calculator", "8"))
self.btn_9.setText(_translate("Calculator", "9"))
self.btn_mult.setText(_translate("Calculator", "×"))
self.btn_4.setText(_translate("Calculator", "4"))
self.btn_plus.setText(_translate("Calculator", "+"))
self.btn_5.setText(_translate("Calculator", "5"))
self.btn_6.setText(_translate("Calculator", "6"))
self.btn_1.setText(_translate("Calculator", "1"))
self.btn_3.setText(_translate("Calculator", "3"))
self.btn_2.setText(_translate("Calculator", "2"))
self.btn_min.setText(_translate("Calculator", "−"))
self.btn_zero.setText(_translate("Calculator", "0"))
self.btn_eq.setText(_translate("Calculator", "="))
self.btn_debug.setText(_translate("Calculator", "DEBUG"))
self.btn_basp.setText(_translate("Calculator", "⌫"))
self.btn_pi.setText(_translate("Calculator", "?"))
self.btn_deg.setText(_translate("Calculator", "x²"))
self.btn_rox.setText(_translate("Calculator", "√"))
self.btn_bl.setText(_translate("Calculator", "("))
self.btn_br.setText(_translate("Calculator", ")"))
class MainWindow(QtWidgets.QMainWindow, Ui_Calculator):
def __init__(self):
super().__init__()
self.setupUi(self)
self.action_plus = 0
self.action_min = 0
self.action_mult = 0
self.action_div = 0
self.action_dot = 0
self.btn_debug.clicked.connect(self.debug)
# зачем два раза ? --------------------------------------> vvv vvv ? <----
# self.btn_zero.clicked.connect(lambda: self.visual("0", "0"))
self.btn_zero.clicked.connect(lambda: self.visual("0"))
self.btn_1.clicked.connect(lambda: self.visual("1"))
self.btn_2.clicked.connect(lambda: self.visual("2"))
self.btn_3.clicked.connect(lambda: self.visual("3"))
self.btn_4.clicked.connect(lambda: self.visual("4"))
self.btn_5.clicked.connect(lambda: self.visual("5"))
self.btn_6.clicked.connect(lambda: self.visual("6"))
self.btn_7.clicked.connect(lambda: self.visual("7"))
self.btn_8.clicked.connect(lambda: self.visual("8"))
self.btn_9.clicked.connect(lambda: self.visual("9"))
self.btn_bl.clicked.connect(lambda: self.visual("("))
self.btn_br.clicked.connect(lambda: self.visual(")"))
self.btn_plus.clicked.connect(lambda: self.visual("+"))
self.btn_min.clicked.connect(lambda: self.visual("-"))
self.btn_mult.clicked.connect(lambda: self.visual("*"))
self.btn_div.clicked.connect(lambda: self.visual("/"))
self.btn_dot.clicked.connect(lambda: self.visual("."))
# ? vvvvvvvvvvvv <---- нет такой кнопки <----------------------- # ???
# ? self.btn_del.clicked.connect(self.delete)
self.btn_c.clicked.connect(self.delete) # ? наверное вы хотели # ???
self.btn_proc.clicked.connect(self.procent)
self.btn_eq.clicked.connect(self.results)
# ? vvvvvvvvvvvvvvvvvv <---- что это <----<----<----<---- # ???
self.input_symbols = ""
self.action = 0
def num_handler(self, num1, num2):
self.input_symbols = str(self.input_symbols)
num1 = str(num1)
num2 = str(num2)
print(f"Нажато: {num1}")
if self.action == 0:
self.action = 1
self.display.setText(num1)
self.input_symbols = num2
else:
self.display.setText(self.display.text()+ num1)
self.input_symbols =+ num2
""" """
def num_in_input_symbols(self, symbol):
self.input_symbols = str(self.input_symbols)
symbol = str(symbol)
if self.action == 0:
self.input_symbols = ""
self.input_symbols = symbol
self.action = 1
else:
self.input_symbols = self.input_symbols + symbol
print(f'Натиснуто: "{symbol}" ')
def visual(self, symbol):
print(symbol)
if self.action == 0:
self.display.setText(symbol)
self.action = 1
else:
self.display.setText(self.display.text()+ symbol)
""" """
def delete(self):
try:
print(f'Змінна input_symbols = {self.input_symbols}')
self.display.setText("0")
self.action = 0
print(f"Pressed? {self.action}")
self.input_symbols = ""
except Exception as e:
print("Error:", e)
def rounding(self, number):
try:
if number % 1 == 0:
return int(number)
else:
return round(number, 8)
except Exception as e:
print("Error:", e)
"""
def rox(self, number):
pass
def deg(self, number):
pass
def basp(self, num):
pass
def pi(self):
pass
"""
def procent(self):
try:
num = self.display.text()
if num.find("+") == -1 and num.find("-") == -1 and num.find("*") == -1 and num.find("/") == -1:
p1 = float(num)
p2 = p1 / 100
self.input_symbols = p2
p2=str(p2)
p2 = p2.replace(".", ",")
self.display.setText(p2)
else:
self.action = 0
except Exception as e:
print("Error:", e)
def results(self):
print(f'1 self.input_symbols = {self.input_symbols} <---- что это ?') #
try:
# ? vvvvvvvvvvvvvvvvvv <---- что это <----<----<----<---- # ???
# r1 = eval(self.input_symbols)
r1 = eval(self.display.text()) # наверное так ???
r2 = self.rounding(r1) # ???
r2 = str(r2) # ???
r2 = r2.replace(".", ",")
self.display.setText(r2)
self.action = 0
except Exception as e:
print("def results(self): Error:", e)
def debug(self):
print(f'''
×--------------------------------------------×
self.display.text() = {self.display.text()}
self.input_symbols = {self.input_symbols}
self.action = {self.action}
--------------------------------------------×''')
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
# НЕТ, это неправильный вызов.
# Calculator = QtWidgets.QMainWindow()
# ui = Ui_Calculator()
# ui.setupUi(Calculator)
# Calculator.show()
# Это ПРАВИЛЬНЫЙ вызов.
calculator = MainWindow() # !!! +++
calculator.show() # !!! +++
sys.exit(app.exec_())