In this PyQt5 article we are going to learn How to Make PyQt5 GUI Calculator,
OK before coding let’s just have a simple introduction to PyQt5.
Also you can check more Python GUI articles in the below links
1: Python TKinter GUI Development
What is PyQt5 ?
PyQt5 is a binding for Qt5 C++ a GUI framework for C++ programming language, PyQt5 is used to write all kinds of GUI applications, from accounting applications, to visualization tools used by scientists and engineers.
it is possible to write PyQt5 applications that are just tens of lines long, and medium-size projects of 1000 to 10000 lines are very common. PyQt5 can be used free of charge for noncommercial purposes, Both PyQt and Qt are dual-licensed: This essentially allows them to be used to develop noncommercial applications which must in turn be licensed using an acceptable open source license such as the GNU General Public License (GPL), or to be used to develop commercial applications in this case, a commercial PyQt license and a commercial Qt license must be purchased.
Installation
You can use pip command for the installation of PyQt5.
1 |
pip install pyqt5 |
So now this is the complete code for our article, there are three different Python files,
the first one is our design, the second one is our logic file and the third one is for runing
our main PyQt5 application.
So this is the design file, the design file of this application is created by Qt Designer.
the file was ui file, but i have converted the file to Python file , and the name of file
is ui_calculator.py.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 |
# -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'dialog.ui' # # Created by: PyQt5 UI code generator 5.9 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Calculator(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(323, 398) self.label = QtWidgets.QLabel(Dialog) self.label.setGeometry(QtCore.QRect(20, 30, 281, 51)) font = QtGui.QFont() font.setPointSize(10) font.setBold(True) font.setWeight(75) self.label.setFont(font) self.label.setStyleSheet("QLabel {\n" "\n" "border:1px solid green;\n" "background-color:white;\n" "qproperty-alignment: \'AlignVCenter | AlignRight\';\n" "\n" "\n" "\n" "}") self.label.setObjectName("label") self.pushButton_clear = QtWidgets.QPushButton(Dialog) self.pushButton_clear.setGeometry(QtCore.QRect(20, 80, 71, 61)) font = QtGui.QFont() font.setPointSize(9) font.setBold(True) font.setWeight(75) self.pushButton_clear.setFont(font) self.pushButton_clear.setStyleSheet("QPushButton {\n" "border:1px solid green;\n" "\n" "background-color:#2AFF55\n" "\n" "\n" "}\n" "\n" "\n" "QPushButton:pressed {\n" "\n" "background-color:#2AFFAA\n" "\n" "\n" "\n" "}") self.pushButton_clear.setObjectName("pushButton_clear") self.pushButton_divide = QtWidgets.QPushButton(Dialog) self.pushButton_divide.setGeometry(QtCore.QRect(230, 80, 71, 61)) font = QtGui.QFont() font.setPointSize(9) font.setBold(True) font.setWeight(75) self.pushButton_divide.setFont(font) self.pushButton_divide.setStyleSheet("QPushButton {\n" "\n" "border:1px solid gree;\n" "background-color:#55FFAA;\n" "\n" "\n" "\n" "}\n" "\n" "\n" "QPushButton:pressed {\n" "\n" "background-color:#AAFFFF;\n" "\n" "\n" "}") self.pushButton_divide.setObjectName("pushButton_divide") self.pushButton_modulus = QtWidgets.QPushButton(Dialog) self.pushButton_modulus.setGeometry(QtCore.QRect(160, 80, 71, 61)) font = QtGui.QFont() font.setPointSize(9) font.setBold(True) font.setWeight(75) self.pushButton_modulus.setFont(font) self.pushButton_modulus.setStyleSheet("QPushButton {\n" "border:1px solid green;\n" "\n" "background-color:#2AFF55\n" "\n" "\n" "}\n" "\n" "\n" "QPushButton:pressed {\n" "\n" "background-color:#2AFFAA\n" "\n" "\n" "\n" "}") self.pushButton_modulus.setObjectName("pushButton_modulus") self.pushButton_plusminus = QtWidgets.QPushButton(Dialog) self.pushButton_plusminus.setGeometry(QtCore.QRect(90, 80, 71, 61)) font = QtGui.QFont() font.setPointSize(9) font.setBold(True) font.setWeight(75) self.pushButton_plusminus.setFont(font) self.pushButton_plusminus.setStyleSheet("QPushButton {\n" "border:1px solid green;\n" "\n" "background-color:#2AFF55\n" "\n" "\n" "}\n" "\n" "\n" "QPushButton:pressed {\n" "\n" "background-color:#2AFFAA\n" "\n" "\n" "\n" "}") self.pushButton_plusminus.setObjectName("pushButton_plusminus") self.pushButton_multiply = QtWidgets.QPushButton(Dialog) self.pushButton_multiply.setGeometry(QtCore.QRect(230, 140, 71, 61)) font = QtGui.QFont() font.setPointSize(9) font.setBold(True) font.setWeight(75) self.pushButton_multiply.setFont(font) self.pushButton_multiply.setStyleSheet("QPushButton {\n" "\n" "border:1px solid gree;\n" "background-color:#55FFAA;\n" "\n" "\n" "\n" "}\n" "\n" "\n" "QPushButton:pressed {\n" "\n" "background-color:#AAFFFF;\n" "\n" "\n" "}") self.pushButton_multiply.setObjectName("pushButton_multiply") self.pushButton_nine = QtWidgets.QPushButton(Dialog) self.pushButton_nine.setGeometry(QtCore.QRect(160, 140, 71, 61)) font = QtGui.QFont() font.setPointSize(9) font.setBold(True) font.setWeight(75) self.pushButton_nine.setFont(font) self.pushButton_nine.setStyleSheet("QPushButton {\n" "\n" "border:1px solid green;\n" "background-color:#AAFFAA;\n" "\n" "\n" "\n" "}\n" "\n" "QPushButton:pressed {\n" "\n" "background-color:#AAFFD4\n" "\n" "\n" "}") self.pushButton_nine.setObjectName("pushButton_nine") self.pushButton_eight = QtWidgets.QPushButton(Dialog) self.pushButton_eight.setGeometry(QtCore.QRect(90, 140, 71, 61)) font = QtGui.QFont() font.setPointSize(9) font.setBold(True) font.setWeight(75) self.pushButton_eight.setFont(font) self.pushButton_eight.setStyleSheet("QPushButton {\n" "\n" "border:1px solid green;\n" "background-color:#AAFFAA;\n" "\n" "\n" "\n" "}\n" "\n" "QPushButton:pressed {\n" "\n" "background-color:#AAFFD4\n" "\n" "\n" "}") self.pushButton_eight.setObjectName("pushButton_eight") self.pushButton_seven = QtWidgets.QPushButton(Dialog) self.pushButton_seven.setGeometry(QtCore.QRect(20, 140, 71, 61)) font = QtGui.QFont() font.setPointSize(9) font.setBold(True) font.setWeight(75) self.pushButton_seven.setFont(font) self.pushButton_seven.setStyleSheet("QPushButton {\n" "\n" "border:1px solid green;\n" "background-color:#AAFFAA;\n" "\n" "\n" "\n" "}\n" "\n" "QPushButton:pressed {\n" "\n" "background-color:#AAFFD4\n" "\n" "\n" "}") self.pushButton_seven.setObjectName("pushButton_seven") self.pushButton_minus = QtWidgets.QPushButton(Dialog) self.pushButton_minus.setGeometry(QtCore.QRect(230, 200, 71, 61)) font = QtGui.QFont() font.setPointSize(9) font.setBold(True) font.setWeight(75) self.pushButton_minus.setFont(font) self.pushButton_minus.setStyleSheet("QPushButton {\n" "\n" "border:1px solid gree;\n" "background-color:#55FFAA;\n" "\n" "\n" "\n" "}\n" "\n" "\n" "QPushButton:pressed {\n" "\n" "background-color:#AAFFFF;\n" "\n" "\n" "}") self.pushButton_minus.setObjectName("pushButton_minus") self.pushButton_four = QtWidgets.QPushButton(Dialog) self.pushButton_four.setGeometry(QtCore.QRect(160, 200, 71, 61)) font = QtGui.QFont() font.setPointSize(9) font.setBold(True) font.setWeight(75) self.pushButton_four.setFont(font) self.pushButton_four.setStyleSheet("QPushButton {\n" "\n" "border:1px solid green;\n" "background-color:#AAFFAA;\n" "\n" "\n" "\n" "}\n" "\n" "QPushButton:pressed {\n" "\n" "background-color:#AAFFD4\n" "\n" "\n" "}") self.pushButton_four.setObjectName("pushButton_four") self.pushButton_five = QtWidgets.QPushButton(Dialog) self.pushButton_five.setGeometry(QtCore.QRect(90, 200, 71, 61)) font = QtGui.QFont() font.setPointSize(9) font.setBold(True) font.setWeight(75) self.pushButton_five.setFont(font) self.pushButton_five.setStyleSheet("QPushButton {\n" "\n" "border:1px solid green;\n" "background-color:#AAFFAA;\n" "\n" "\n" "\n" "}\n" "\n" "QPushButton:pressed {\n" "\n" "background-color:#AAFFD4\n" "\n" "\n" "}") self.pushButton_five.setObjectName("pushButton_five") self.pushButton_six = QtWidgets.QPushButton(Dialog) self.pushButton_six.setGeometry(QtCore.QRect(20, 200, 71, 61)) font = QtGui.QFont() font.setPointSize(9) font.setBold(True) font.setWeight(75) self.pushButton_six.setFont(font) self.pushButton_six.setStyleSheet("QPushButton {\n" "\n" "border:1px solid green;\n" "background-color:#AAFFAA;\n" "\n" "\n" "\n" "}\n" "\n" "QPushButton:pressed {\n" "\n" "background-color:#AAFFD4\n" "\n" "\n" "}") self.pushButton_six.setObjectName("pushButton_six") self.pushButton_plus = QtWidgets.QPushButton(Dialog) self.pushButton_plus.setGeometry(QtCore.QRect(230, 260, 71, 61)) font = QtGui.QFont() font.setPointSize(9) font.setBold(True) font.setWeight(75) self.pushButton_plus.setFont(font) self.pushButton_plus.setStyleSheet("QPushButton {\n" "\n" "border:1px solid gree;\n" "background-color:#55FFAA;\n" "\n" "\n" "\n" "}\n" "\n" "\n" "QPushButton:pressed {\n" "\n" "background-color:#AAFFFF;\n" "\n" "\n" "}") self.pushButton_plus.setObjectName("pushButton_plus") self.pushButton_one = QtWidgets.QPushButton(Dialog) self.pushButton_one.setGeometry(QtCore.QRect(160, 260, 71, 61)) font = QtGui.QFont() font.setPointSize(9) font.setBold(True) font.setWeight(75) self.pushButton_one.setFont(font) self.pushButton_one.setStyleSheet("QPushButton {\n" "\n" "border:1px solid green;\n" "background-color:#AAFFAA;\n" "\n" "\n" "\n" "}\n" "\n" "QPushButton:pressed {\n" "\n" "background-color:#AAFFD4\n" "\n" "\n" "}") self.pushButton_one.setObjectName("pushButton_one") self.pushButton_two = QtWidgets.QPushButton(Dialog) self.pushButton_two.setGeometry(QtCore.QRect(90, 260, 71, 61)) font = QtGui.QFont() font.setPointSize(9) font.setBold(True) font.setWeight(75) self.pushButton_two.setFont(font) self.pushButton_two.setStyleSheet("QPushButton {\n" "\n" "border:1px solid green;\n" "background-color:#AAFFAA;\n" "\n" "\n" "\n" "}\n" "\n" "QPushButton:pressed {\n" "\n" "background-color:#AAFFD4\n" "\n" "\n" "}") self.pushButton_two.setObjectName("pushButton_two") self.pushButton_three = QtWidgets.QPushButton(Dialog) self.pushButton_three.setGeometry(QtCore.QRect(20, 260, 71, 61)) font = QtGui.QFont() font.setPointSize(9) font.setBold(True) font.setWeight(75) self.pushButton_three.setFont(font) self.pushButton_three.setStyleSheet("QPushButton {\n" "\n" "border:1px solid green;\n" "background-color:#AAFFAA;\n" "\n" "\n" "\n" "}\n" "\n" "QPushButton:pressed {\n" "\n" "background-color:#AAFFD4\n" "\n" "\n" "}") self.pushButton_three.setObjectName("pushButton_three") self.pushButton_zero = QtWidgets.QPushButton(Dialog) self.pushButton_zero.setGeometry(QtCore.QRect(20, 320, 141, 61)) font = QtGui.QFont() font.setPointSize(9) font.setBold(True) font.setWeight(75) self.pushButton_zero.setFont(font) self.pushButton_zero.setStyleSheet("QPushButton {\n" "\n" "border:1px solid green;\n" "background-color:#AAFFAA;\n" "\n" "\n" "\n" "}\n" "\n" "QPushButton:pressed {\n" "\n" "background-color:#AAFFD4\n" "\n" "\n" "}") self.pushButton_zero.setObjectName("pushButton_zero") self.pushButton_equal = QtWidgets.QPushButton(Dialog) self.pushButton_equal.setGeometry(QtCore.QRect(230, 320, 71, 61)) font = QtGui.QFont() font.setPointSize(9) font.setBold(True) font.setWeight(75) self.pushButton_equal.setFont(font) self.pushButton_equal.setStyleSheet("QPushButton {\n" "\n" "border:1px solid gree;\n" "background-color:#55FFAA;\n" "\n" "\n" "\n" "}\n" "\n" "\n" "QPushButton:pressed {\n" "\n" "background-color:#AAFFFF;\n" "\n" "\n" "}") self.pushButton_equal.setObjectName("pushButton_equal") self.pushButton_decimel = QtWidgets.QPushButton(Dialog) self.pushButton_decimel.setGeometry(QtCore.QRect(160, 320, 71, 61)) font = QtGui.QFont() font.setPointSize(9) font.setBold(True) font.setWeight(75) self.pushButton_decimel.setFont(font) self.pushButton_decimel.setStyleSheet("QPushButton {\n" "border:1px solid green;\n" "\n" "background-color:#2AFF55\n" "\n" "\n" "}\n" "\n" "\n" "QPushButton:pressed {\n" "\n" "background-color:#2AFFAA\n" "\n" "\n" "\n" "}") self.pushButton_decimel.setObjectName("pushButton_decimel") self.retranslateUi(Dialog) QtCore.QMetaObject.connectSlotsByName(Dialog) def retranslateUi(self, Dialog): _translate = QtCore.QCoreApplication.translate Dialog.setWindowTitle(_translate("Dialog", "Dialog")) self.label.setText(_translate("Dialog", "0")) self.pushButton_clear.setText(_translate("Dialog", "C")) self.pushButton_divide.setText(_translate("Dialog", "/")) self.pushButton_modulus.setText(_translate("Dialog", "%")) self.pushButton_plusminus.setText(_translate("Dialog", "+/-")) self.pushButton_multiply.setText(_translate("Dialog", "x")) self.pushButton_nine.setText(_translate("Dialog", "9")) self.pushButton_eight.setText(_translate("Dialog", "8")) self.pushButton_seven.setText(_translate("Dialog", "7")) self.pushButton_minus.setText(_translate("Dialog", "-")) self.pushButton_four.setText(_translate("Dialog", "4")) self.pushButton_five.setText(_translate("Dialog", "5")) self.pushButton_six.setText(_translate("Dialog", "6")) self.pushButton_plus.setText(_translate("Dialog", "+")) self.pushButton_one.setText(_translate("Dialog", "1")) self.pushButton_two.setText(_translate("Dialog", "2")) self.pushButton_three.setText(_translate("Dialog", "3")) self.pushButton_zero.setText(_translate("Dialog", "0")) self.pushButton_equal.setText(_translate("Dialog", "=")) self.pushButton_decimel.setText(_translate("Dialog", ".")) |
This is our main logic file and i have called it calculator.py.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
from PyQt5 import QtWidgets from ui_calculator import Ui_Calculator class calculatorWindow(QtWidgets.QMainWindow, Ui_Calculator): firNumber = None typingNumber = False def __init__(self): super().__init__() self.setupUi(self) self.show() #our buttons self.pushButton_zero.clicked.connect(self.numberPressed) self.pushButton_one.clicked.connect(self.numberPressed) self.pushButton_two.clicked.connect(self.numberPressed) self.pushButton_three.clicked.connect(self.numberPressed) self.pushButton_four.clicked.connect(self.numberPressed) self.pushButton_five.clicked.connect(self.numberPressed) self.pushButton_six.clicked.connect(self.numberPressed) self.pushButton_seven.clicked.connect(self.numberPressed) self.pushButton_eight.clicked.connect(self.numberPressed) self.pushButton_nine.clicked.connect(self.numberPressed) self.pushButton_decimel.clicked.connect(self.decimalPressed) self.pushButton_plusminus.clicked.connect(self.unaryOperation) self.pushButton_modulus.clicked.connect(self.unaryOperation) self.pushButton_plus.clicked.connect(self.binaryOperation) self.pushButton_minus.clicked.connect(self.binaryOperation) self.pushButton_multiply.clicked.connect(self.binaryOperation) self.pushButton_divide.clicked.connect(self.binaryOperation) self.pushButton_equal.clicked.connect(self.equl_pressed) self.pushButton_clear.clicked.connect(self.clearbtn) self.pushButton_plus.setCheckable(True) self.pushButton_minus.setCheckable(True) self.pushButton_multiply.setCheckable(True) self.pushButton_divide.setCheckable(True) #number pressed method def numberPressed(self): button = self.sender() if (( self.pushButton_plus.isChecked() or self.pushButton_minus.isChecked() or self.pushButton_divide.isChecked() or self.pushButton_multiply.isChecked()) and ( not self.typingNumber)): lbl = format(float(button.text()), '.15g') self.typingNumber = True else: if (('.' in self.label.text()) and (button.text() == '0')): lbl = format(self.label.text() + button.text(), '.15') else: lbl = format(float(self.label.text() + button.text()), '.15g') self.label.setText(lbl) #decimel number pressed def decimalPressed(self): self.label.setText(self.label.text() + '.') #unaryopertio def unaryOperation(self): button = self.sender() labelNumber = float(self.label.text()) if button.text() == "+/-": labelNumber = labelNumber * -1 else: labelNumber = labelNumber * 0.01 newLabel = format(labelNumber, '.15g') self.label.setText(newLabel) #binary operation def binaryOperation(self): button = self.sender() self.firNumber = float(self.label.text()) button.setChecked(True) def equl_pressed(self): secondNumber = float(self.label.text()) if(self.pushButton_plus.isChecked()): labelNumber = self.firNumber + secondNumber newLabel = format(labelNumber, '.15g') self.label.setText(newLabel) self.pushButton_plus.setChecked(False) elif (self.pushButton_minus.isChecked()): labelNumber = self.firNumber - secondNumber newLabel = format(labelNumber, '.15g') self.label.setText(newLabel) self.pushButton_minus.setChecked(False) elif (self.pushButton_multiply.isChecked()): labelNumber = self.firNumber * secondNumber newLabel = format(labelNumber, '.15g') self.label.setText(newLabel) self.pushButton_multiply.setChecked(False) elif (self.pushButton_divide.isChecked()): labelNumber = self.firNumber / secondNumber newLabel = format(labelNumber, '.15g') self.label.setText(newLabel) self.pushButton_divide.setChecked(False) self.typingNumber = False def clearbtn(self): self.pushButton_plus.setChecked(False) self.pushButton_minus.setChecked(False) self.pushButton_multiply.setChecked(False) self.pushButton_divide.setChecked(False) self.typingNumber = False self.label.setText("0") |
So this line of code is for importing our ui file.
1 2 |
from PyQt5 import QtWidgets from ui_calculator import Ui_Calculator |
We have created a main class that extends from the QMainWindow and also our
UI_Calculator class. you can see that we have added two variables in this class that we
will use them.
1 2 |
firNumber = None typingNumber = False |
These are our QPushButton, that we are going to connect this with the specific methods or slot.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
self.pushButton_zero.clicked.connect(self.numberPressed) self.pushButton_one.clicked.connect(self.numberPressed) self.pushButton_two.clicked.connect(self.numberPressed) self.pushButton_three.clicked.connect(self.numberPressed) self.pushButton_four.clicked.connect(self.numberPressed) self.pushButton_five.clicked.connect(self.numberPressed) self.pushButton_six.clicked.connect(self.numberPressed) self.pushButton_seven.clicked.connect(self.numberPressed) self.pushButton_eight.clicked.connect(self.numberPressed) self.pushButton_nine.clicked.connect(self.numberPressed) self.pushButton_decimel.clicked.connect(self.decimalPressed) self.pushButton_plusminus.clicked.connect(self.unaryOperation) self.pushButton_modulus.clicked.connect(self.unaryOperation) self.pushButton_plus.clicked.connect(self.binaryOperation) self.pushButton_minus.clicked.connect(self.binaryOperation) self.pushButton_multiply.clicked.connect(self.binaryOperation) self.pushButton_divide.clicked.connect(self.binaryOperation) self.pushButton_equal.clicked.connect(self.equl_pressed) self.pushButton_clear.clicked.connect(self.clearbtn) |
also we have connected these buttons to specific method or slot.
OK now this is our third file and i have named it main.py, in here we are going to
run our application.
1 2 3 4 5 6 7 8 9 10 11 |
import sys from PyQt5.QtWidgets import QApplication from calculator import calculatorWindow app = QApplication(sys.argv) calculator = calculatorWindow() sys.exit(app.exec()) |
So in here every PyQt5 application must create an application object.
1 |
app = QApplication(sys.argv) |
also we enter the mainloop of the application. The event handling starts from this point.
1 |
sys.exit(app.exec()) |
If you run the code this will be the result, you need to run the code from main.py file.
Subscribe and Get Free Video Courses & Articles in your Email
Thanks for this article.