I am making a simple visual calculator in PyQt5. I haven't really gone to the actual calculator part because I'm having trouble with the buttons. This is the code:
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication, QWidget, QPushButton, QAction, QLineEdit, QMessageBox
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import pyqtSlot
class App(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setWindowTitle('Calculator')
self.setGeometry(100, 100, 4000, 1400)
self.num1= QLineEdit(self)
self.num1.move(20, 20)
self.num1.resize(280,40)
self.num2 = QLineEdit(self)
self.num2.move(20, 100)
self.num2.resize(280,40)
#minus button
self.minus = QPushButton('-' , self)
self.minus.move(80,180)
self.minus.resize(20,40)
self.minus.clicked.connect(self.minus_onclick)
self.show()
#plus button
self.plus = QPushButton('+' , self)
self.plus.move(20,180)
self.plus.resize(20,40)
self.plus.clicked.connect(self.plus_onclick)
self.show()
#* button
self.into = QPushButton('*' , self)
self.into.move(140, 180)
self.into.resize(20, 40)
self.into.clicked.connect(self.into_onclick)
self.show()
#division button
self.div = QPushButton('/' , self)
self.div.move(140, 180)
self.div.resize(20, 40)
self.div.clicked.connect(self.div_onclick)
self.show()
def plus_onclick(self):
num1 =int(self.num1.text())
op = '+'
def minus_onclick(self):
num1 =int(self.num1.text())
op = '-'
def into_onclick(self):
num1 =int(self.num1.text())
op = '*'
def div_onclick(self):
num1 =int(self.num1.text())
op = '/'
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())
However, the problem is that only the first button works and is shown on the screen, no matter which one it is. What am I doing wrong? Thanks in advance
self.show(). Leave one - the last.