Tenho essas linhas de comando, mas contem algum erro.
Line1 * Line2
botão: multiplica
resutlado: line3
from PyQt6 import QtCore, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(“MainWindow”)
MainWindow.resize(530, 319)
self.centralwidget = QtWidgets.QWidget(parent=MainWindow)
self.centralwidget.setObjectName(“centralwidget”)
self.line1 = QtWidgets.QLineEdit(parent=self.centralwidget)
self.line1.setGeometry(QtCore.QRect(50, 80, 81, 41))
self.line1.setStyleSheet(“font: 75 24pt "MS Shell Dlg 2";”)
self.line1.setObjectName(“line1”)
self.line2 = QtWidgets.QLineEdit(parent=self.centralwidget)
self.line2.setGeometry(QtCore.QRect(170, 80, 81, 41))
self.line2.setStyleSheet(“font: 75 24pt "MS Shell Dlg 2";”)
self.line2.setObjectName(“line2”)
self.line3 = QtWidgets.QLineEdit(parent=self.centralwidget)
self.line3.setGeometry(QtCore.QRect(310, 80, 113, 41))
self.line3.setStyleSheet(“font: 75 24pt "MS Shell Dlg 2";”)
self.line3.setObjectName(“line3”)
self.multiplica = QtWidgets.QPushButton(parent=self.centralwidget)
self.multiplica.setGeometry(QtCore.QRect(160, 130, 91, 41))
self.multiplica.setStyleSheet(“background-color: rgb(255, 170, 0);\n”
“font: 18pt "MS Shell Dlg 2";\n”
“color: rgb(0, 0, 0);”)
self.multiplica.setObjectName(“multiplica”)
self.label = QtWidgets.QLabel(parent=self.centralwidget)
self.label.setGeometry(QtCore.QRect(140, 80, 21, 41))
self.label.setStyleSheet(“font: 75 28pt "MS Shell Dlg 2";”)
self.label.setObjectName(“label”)
self.label_2 = QtWidgets.QLabel(parent=self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(270, 80, 21, 41))
self.label_2.setStyleSheet(“font: 75 28pt "MS Shell Dlg 2";”)
self.label_2.setObjectName(“label_2”)
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.multiplica.setText(_translate("MainWindow", "Calcular"))
self.label.setText(_translate("MainWindow", "X"))
self.label_2.setText(_translate("MainWindow", "="))
self.multiplica.clicked.connect(self.formula)
def formula(self):
preco=int(self.line1.getText())
desc=int(self.line2.getText())
pago = preco * desc
self.line3.setText(str(pago))
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())