import sys from PyQt5.QtWidgets import QApplication, QMainWindow from PyQt5.QtWidgets import QLabel, QLineEdit, QPushButton class MainWindow(QMainWindow): def __init__(self): super().__init__() baseLabel = QLabel(self) baseLabel.setText('Alap') baseLabel.move(50, 30) self.baseEntry = QLineEdit(self) self.baseEntry.move(130, 30) heightLabel = QLabel(self) heightLabel.setText('Magasság') heightLabel.move(50, 70) self.heightEnty = QLineEdit(self) self.heightEnty.move(130, 70) calcButton = QPushButton(self) calcButton.setText('Számít') calcButton.move(90, 120) calcButton.clicked.connect(self.on_click_calcbutton) areaLabel = QLabel(self) areaLabel.setText('Terület') areaLabel.move(50, 160) self.areaEnty = QLineEdit(self) self.areaEnty.move(130, 160) self.setGeometry(100,100,320,200) self.setWindowTitle('Háromszög területe') self.show() def on_click_calcbutton(self): base = int(self.baseEntry.text()) height = int(self.heightEnty.text()) area = base * height / 2 self.areaEnty.setText(str(area)) self.baseEntry.setText('') self.heightEnty.setText('') if __name__ == '__main__': app = QApplication(sys.argv) mainWindow = MainWindow() sys.exit(app.exec_())