я создал калькулятор на Pyside2 и перевел ui формат в py. Как сделать так чтобы кнопки заработали когда нажимаешь и чтобы деления и умножения и вычитания и сложения тоже работали Вот собственно и код:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'org.ui'
#
# Created by: PyQt5 UI code generator 5.13.2
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.gridLayoutWidget = QtWidgets.QWidget(self.centralwidget)
self.gridLayoutWidget.setGeometry(QtCore.QRect(120, 150, 431, 321))
self.gridLayoutWidget.setObjectName("gridLayoutWidget")
self.gridLayout = QtWidgets.QGridLayout(self.gridLayoutWidget)
self.gridLayout.setContentsMargins(0, 0, 0, 0)
self.gridLayout.setObjectName("gridLayout")
self.pushButton_8 = QtWidgets.QPushButton(self.gridLayoutWidget)
self.pushButton_8.setStyleSheet("font: 18pt \"MS Shell Dlg 2\";")
self.pushButton_8.setObjectName("pushButton_8")
self.gridLayout.addWidget(self.pushButton_8, 2, 0, 1, 1)
self.pushButton_5 = QtWidgets.QPushButton(self.gridLayoutWidget)
self.pushButton_5.setStyleSheet("font: 18pt \"MS Shell Dlg 2\";")
self.pushButton_5.setObjectName("pushButton_5")
self.gridLayout.addWidget(self.pushButton_5, 0, 1, 1, 1)
self.pushButton_10 = QtWidgets.QPushButton(self.gridLayoutWidget)
self.pushButton_10.setStyleSheet("font: 18pt \"MS Shell Dlg 2\";")
self.pushButton_10.setObjectName("pushButton_10")
self.gridLayout.addWidget(self.pushButton_10, 0, 0, 1, 1)
self.pushButton_2 = QtWidgets.QPushButton(self.gridLayoutWidget)
self.pushButton_2.setStyleSheet("font: 18pt \"MS Shell Dlg 2\";")
self.pushButton_2.setObjectName("pushButton_2")
self.gridLayout.addWidget(self.pushButton_2, 2, 3, 1, 1)
self.pushButton_6 = QtWidgets.QPushButton(self.gridLayoutWidget)
self.pushButton_6.setStyleSheet("font: 18pt \"MS Shell Dlg 2\";")
self.pushButton_6.setObjectName("pushButton_6")
self.gridLayout.addWidget(self.pushButton_6, 1, 1, 1, 1)
self.pushButton_3 = QtWidgets.QPushButton(self.gridLayoutWidget)
self.pushButton_3.setStyleSheet("font: 18pt \"MS Shell Dlg 2\";")
self.pushButton_3.setObjectName("pushButton_3")
self.gridLayout.addWidget(self.pushButton_3, 1, 3, 1, 1)
self.pushButton = QtWidgets.QPushButton(self.gridLayoutWidget)
self.pushButton.setStyleSheet("font: 18pt \"MS Shell Dlg 2\";")
self.pushButton.setObjectName("pushButton")
self.gridLayout.addWidget(self.pushButton, 2, 1, 1, 1)
self.pushButton_4 = QtWidgets.QPushButton(self.gridLayoutWidget)
self.pushButton_4.setStyleSheet("font: 18pt \"MS Shell Dlg 2\";")
self.pushButton_4.setObjectName("pushButton_4")
self.gridLayout.addWidget(self.pushButton_4, 0, 3, 1, 1)
self.pushButton_9 = QtWidgets.QPushButton(self.gridLayoutWidget)
self.pushButton_9.setStyleSheet("font: 18pt \"MS Shell Dlg 2\";")
self.pushButton_9.setObjectName("pushButton_9")
self.gridLayout.addWidget(self.pushButton_9, 1, 0, 1, 1)
self.pushButton_11 = QtWidgets.QPushButton(self.gridLayoutWidget)
self.pushButton_11.setStyleSheet("font: 18pt \"MS Shell Dlg 2\";")
self.pushButton_11.setObjectName("pushButton_11")
self.gridLayout.addWidget(self.pushButton_11, 3, 0, 1, 1)
self.pushButton_7 = QtWidgets.QPushButton(self.gridLayoutWidget)
self.pushButton_7.setStyleSheet("font: 18pt \"MS Shell Dlg 2\";")
self.pushButton_7.setObjectName("pushButton_7")
self.gridLayout.addWidget(self.pushButton_7, 3, 1, 1, 1)
self.pushButton_16 = QtWidgets.QPushButton(self.gridLayoutWidget)
self.pushButton_16.setStyleSheet("font: 18pt \"MS Shell Dlg 2\";")
self.pushButton_16.setObjectName("pushButton_16")
self.gridLayout.addWidget(self.pushButton_16, 3, 3, 1, 1)
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(110, 50, 431, 81))
self.lineEdit.setObjectName("lineEdit")
self.pushButton_12 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_12.setGeometry(QtCore.QRect(670, 150, 75, 51))
self.pushButton_12.setStyleSheet("font: 18pt \"MS Shell Dlg 2\";")
self.pushButton_12.setObjectName("pushButton_12")
self.pushButton_13 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_13.setGeometry(QtCore.QRect(670, 230, 75, 51))
self.pushButton_13.setStyleSheet("font: 18pt \"MS Shell Dlg 2\";")
self.pushButton_13.setObjectName("pushButton_13")
self.pushButton_14 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_14.setGeometry(QtCore.QRect(670, 310, 75, 51))
self.pushButton_14.setStyleSheet("font: 18pt \"MS Shell Dlg 2\";")
self.pushButton_14.setObjectName("pushButton_14")
self.pushButton_15 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_15.setGeometry(QtCore.QRect(670, 390, 75, 51))
self.pushButton_15.setStyleSheet("font: 18pt \"MS Shell Dlg 2\";")
self.pushButton_15.setObjectName("pushButton_15")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.action1 = QtWidgets.QAction(MainWindow)
self.action1.setCheckable(True)
self.action1.setObjectName("action1")
self.retranslateUi(MainWindow)
self.pushButton_16.pressed.connect(self.lineEdit.clear)
self.pushButton_10.clicked.connect(self.lineEdit.clear)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton_8.setText(_translate("MainWindow", "7"))
self.pushButton_5.setText(_translate("MainWindow", "2"))
self.pushButton_10.setText(_translate("MainWindow", "1"))
self.pushButton_2.setText(_translate("MainWindow", "9"))
self.pushButton_6.setText(_translate("MainWindow", "5"))
self.pushButton_3.setText(_translate("MainWindow", "6"))
self.pushButton.setText(_translate("MainWindow", "8"))
self.pushButton_4.setText(_translate("MainWindow", "3"))
self.pushButton_9.setText(_translate("MainWindow", "4"))
self.pushButton_11.setText(_translate("MainWindow", "0"))
self.pushButton_7.setText(_translate("MainWindow", "="))
self.pushButton_16.setText(_translate("MainWindow", "Очистить"))
self.pushButton_12.setText(_translate("MainWindow", "/"))
self.pushButton_13.setText(_translate("MainWindow", "*"))
self.pushButton_14.setText(_translate("MainWindow", "+"))
self.pushButton_15.setText(_translate("MainWindow", "-"))
self.action1.setText(_translate("MainWindow", "1"))
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_())