Repository: PacktPublishing/Qt5-Python-GUI-Programming-Cookbook Branch: master Commit: 2faa44cd090e Files: 94 Total size: 220.9 KB Directory structure: gitextract_2qkmchcu/ ├── Chapter01/ │ ├── callCheckBox1.pyw │ ├── callCheckBox2.pyw │ ├── callLineEdit.pyw │ ├── callRadioButton1.pyw │ ├── callRadioButton2.pyw │ ├── demoCheckBox1.py │ ├── demoCheckBox2.py │ ├── demoCheckbox1.ui │ ├── demoCheckbox2.ui │ ├── demoLineEdit.py │ ├── demoLineEdit.ui │ ├── demoRadioButton1.py │ ├── demoRadioButton1.ui │ ├── demoRadioButton2.py │ └── demoRadioButton2.ui ├── Chapter02/ │ ├── callCalculator.pyw │ ├── callComboBox.pyw │ ├── callFontComboBox.pyw │ ├── callListWidget1.pyw │ ├── callListWidget2.pyw │ ├── callListWidget3.pyw │ ├── callListWidgetOp.pyw │ ├── callProgressBar.pyw │ ├── callScrollBar.pyw │ ├── calldemoSignalSlot1.pyw │ ├── calldemoSpinner.pyw │ ├── demoCalculator.py │ ├── demoCalculator.ui │ ├── demoComboBox.py │ ├── demoComboBox.ui │ ├── demoFontComboBox.py │ ├── demoFontComboBox.ui │ ├── demoListWidget1.py │ ├── demoListWidget1.ui │ ├── demoListWidget2.py │ ├── demoListWidget2.ui │ ├── demoListWidget3.py │ ├── demoListWidget3.ui │ ├── demoListWidgetOp.py │ ├── demoListWidgetOp.ui │ ├── demoProgressBar.py │ ├── demoProgressBar.ui │ ├── demoScrollBar.py │ ├── demoScrollBar.ui │ ├── demoSignalSlot1.py │ ├── demoSignalSlot1.ui │ ├── demoSpinBox.py │ └── demoSpinBox.ui ├── Chapter03/ │ ├── DemoTableWidget.ui │ ├── callCalendar.pyw │ ├── callLCD.pyw │ ├── callTableWidget.pyw │ ├── computeRoomRent.pyw │ ├── demoCalendar.py │ ├── demoCalendar.ui │ ├── demoLCD.py │ ├── demoLCD.ui │ ├── demoTabWidget.py │ ├── reservehotel.py │ └── reservehotel.ui ├── Chapter04/ │ ├── LineEditClass.py │ ├── LineEditClass.ui │ ├── callLineEditClass.pyw │ ├── callMultilevelInheritance.pyw │ ├── callMultipleInheritance.pyw │ ├── callSimpleInheritance.pyw │ ├── callStudentClass.pyw │ ├── demoMultilevelInheritance.py │ ├── demoMultilevelInheritance.ui │ ├── demoMultipleInheritance.py │ ├── demoMultipleInheritance.ui │ ├── demoSimpleInheritance.py │ ├── demoSimpleInheritance.ui │ ├── demoStudentClass.py │ └── demoStudentClass.ui ├── Chapter05/ │ ├── callColorDialog.pyw │ ├── callFileDialog.pyw │ ├── callFontDialog.pyw │ ├── callInputDialog.pyw │ ├── demoColorDialog.py │ ├── demoColorDialog.ui │ ├── demoFileDialog.py │ ├── demoFileDialog.ui │ ├── demoFontDialog.py │ ├── demoFontDialog.ui │ ├── demoInputDialog.py │ └── demoInputDialog.ui ├── Chapter07/ │ ├── callServer.pyw │ ├── demoBrowser.py │ ├── demoDockWidget.ui │ ├── demoMenuBar.py │ └── demoTabWidget.ui ├── LICENSE └── README.md ================================================ FILE CONTENTS ================================================ ================================================ FILE: Chapter01/callCheckBox1.pyw ================================================ import sys from PyQt5.QtWidgets import QDialog from PyQt5.QtWidgets import QApplication, QWidget, QPushButton from PyQt5.QtCore import pyqtSlot from demoCheckBox1 import * class MyForm(QDialog): def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.ui.checkBoxCheese.stateChanged.connect(self.dispAmount) self.ui.checkBoxOlives.stateChanged.connect(self.dispAmount) self.ui.checkBoxSausages.stateChanged.connect(self.dispAmount) self.show() @pyqtSlot() def dispAmount(self): amount=10 if self.ui.checkBoxCheese.isChecked()==True: amount=amount+1 if self.ui.checkBoxOlives.isChecked()==True: amount=amount+1 if self.ui.checkBoxSausages.isChecked()==True: amount=amount+2 self.ui.labelAmount.setText("Total amount for pizza is "+str(amount)) if __name__=="__main__": app = QApplication(sys.argv) w = MyForm() w.show() sys.exit(app.exec_()) ================================================ FILE: Chapter01/callCheckBox2.pyw ================================================ import sys from PyQt5.QtWidgets import QDialog from PyQt5.QtWidgets import QApplication, QWidget, QPushButton from PyQt5.QtCore import pyqtSlot from demoCheckBox2 import * class MyForm(QDialog): def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.ui.checkBoxChoclateAlmond.stateChanged.connect(self.dispAmount) self.ui.checkBoxChoclateChips.stateChanged.connect(self.dispAmount) self.ui.checkBoxCookieDough.stateChanged.connect(self.dispAmount) self.ui.checkBoxRockyRoad.stateChanged.connect(self.dispAmount) self.ui.checkBoxCoffee.stateChanged.connect(self.dispAmount) self.ui.checkBoxSoda.stateChanged.connect(self.dispAmount) self.ui.checkBoxTea.stateChanged.connect(self.dispAmount) self.show() @pyqtSlot() def dispAmount(self): amount=0 if self.ui.checkBoxChoclateAlmond.isChecked()==True: amount=amount+3 if self.ui.checkBoxChoclateChips.isChecked()==True: amount=amount+4 if self.ui.checkBoxCookieDough.isChecked()==True: amount=amount+2 if self.ui.checkBoxRockyRoad.isChecked()==True: amount=amount+5 if self.ui.checkBoxCoffee.isChecked()==True: amount=amount+2 if self.ui.checkBoxSoda.isChecked()==True: amount=amount+3 if self.ui.checkBoxTea.isChecked()==True: amount=amount+1 self.ui.labelAmount.setText("Total amount is $"+str(amount)) if __name__=="__main__": app = QApplication(sys.argv) w = MyForm() w.show() sys.exit(app.exec_()) ================================================ FILE: Chapter01/callLineEdit.pyw ================================================ import sys from PyQt5.QtWidgets import QDialog, QApplication from demoLineEdit import * class MyForm(QDialog): def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.ui.ButtonClickMe.clicked.connect(self.dispmessage) self.show() def dispmessage(self): self.ui.labelResponse.setText("Hello "+self.ui.lineEditName.text()) if __name__=="__main__": app = QApplication(sys.argv) w = MyForm() w.show() sys.exit(app.exec_()) ================================================ FILE: Chapter01/callRadioButton1.pyw ================================================ import sys from PyQt5.QtWidgets import QDialog, QApplication from demoRadioButton1 import * class MyForm(QDialog): def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.ui.radioButtonFirstClass.toggled.connect(self.dispFare) self.ui.radioButtonBusinessClass.toggled.connect(self.dispFare) self.ui.radioButtonEconomyClass.toggled.connect(self.dispFare) self.show() def dispFare(self): fare=0 if self.ui.radioButtonFirstClass.isChecked()==True: fare=150 if self.ui.radioButtonBusinessClass.isChecked()==True: fare=125 if self.ui.radioButtonEconomyClass.isChecked()==True: fare=100 self.ui.labelFare.setText("Air Fare is "+str(fare)) if __name__=="__main__": app = QApplication(sys.argv) w = MyForm() w.show() sys.exit(app.exec_()) ================================================ FILE: Chapter01/callRadioButton2.pyw ================================================ import sys from PyQt5.QtWidgets import QDialog, QApplication from demoRadioButton2 import * class MyForm(QDialog): def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.ui.radioButtonMedium.toggled.connect(self.dispSelected) self.ui.radioButtonLarge.toggled.connect(self.dispSelected) self.ui.radioButtonXL.toggled.connect(self.dispSelected) self.ui.radioButtonXXL.toggled.connect(self.dispSelected) self.ui.radioButtonDebitCard.toggled.connect(self.dispSelected) self.ui.radioButtonNetBanking.toggled.connect(self.dispSelected) self.ui.radioButtonCashOnDelivery.toggled.connect(self.dispSelected) self.show() def dispSelected(self): selected1=""; selected2="" if self.ui.radioButtonMedium.isChecked()==True: selected1="Medium" if self.ui.radioButtonLarge.isChecked()==True: selected1="Large" if self.ui.radioButtonXL.isChecked()==True: selected1="Extra Large" if self.ui.radioButtonXXL.isChecked()==True: selected1="Extra Extra Large" if self.ui.radioButtonDebitCard.isChecked()==True: selected2="Debit/Credit Card" if self.ui.radioButtonNetBanking.isChecked()==True: selected2="NetBanking" if self.ui.radioButtonCashOnDelivery.isChecked()==True: selected2="Cash On Delivery" self.ui.labelSelected.setText("Chosen shirt size is "+selected1+" and payment method as " + selected2) if __name__=="__main__": app = QApplication(sys.argv) w = MyForm() w.show() sys.exit(app.exec_()) ================================================ FILE: Chapter01/demoCheckBox1.py ================================================ # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'demoCheckBox1.ui' # # Created by: PyQt5 UI code generator 5.6 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(503, 272) self.label = QtWidgets.QLabel(Dialog) self.label.setGeometry(QtCore.QRect(130, 0, 221, 31)) font = QtGui.QFont() font.setPointSize(14) self.label.setFont(font) self.label.setObjectName("label") self.label_2 = QtWidgets.QLabel(Dialog) self.label_2.setGeometry(QtCore.QRect(20, 50, 251, 31)) font = QtGui.QFont() font.setPointSize(14) self.label_2.setFont(font) self.label_2.setObjectName("label_2") self.checkBoxCheese = QtWidgets.QCheckBox(Dialog) self.checkBoxCheese.setGeometry(QtCore.QRect(270, 60, 191, 17)) font = QtGui.QFont() font.setPointSize(14) self.checkBoxCheese.setFont(font) self.checkBoxCheese.setObjectName("checkBoxCheese") self.checkBoxOlives = QtWidgets.QCheckBox(Dialog) self.checkBoxOlives.setGeometry(QtCore.QRect(270, 90, 241, 21)) font = QtGui.QFont() font.setPointSize(14) self.checkBoxOlives.setFont(font) self.checkBoxOlives.setObjectName("checkBoxOlives") self.checkBoxSausages = QtWidgets.QCheckBox(Dialog) self.checkBoxSausages.setGeometry(QtCore.QRect(270, 120, 231, 17)) font = QtGui.QFont() font.setPointSize(14) self.checkBoxSausages.setFont(font) self.checkBoxSausages.setObjectName("checkBoxSausages") self.labelAmount = QtWidgets.QLabel(Dialog) self.labelAmount.setGeometry(QtCore.QRect(50, 190, 371, 20)) font = QtGui.QFont() font.setPointSize(14) self.labelAmount.setFont(font) self.labelAmount.setObjectName("labelAmount") 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", "Regular Pizza $10")) self.label_2.setText(_translate("Dialog", "Select your extra toppings")) self.checkBoxCheese.setText(_translate("Dialog", "Extra Cheese $1")) self.checkBoxOlives.setText(_translate("Dialog", "Extra Olives $1")) self.checkBoxSausages.setText(_translate("Dialog", "Extra Sausages $2")) self.labelAmount.setText(_translate("Dialog", "TextLabel")) if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) Dialog = QtWidgets.QDialog() ui = Ui_Dialog() ui.setupUi(Dialog) Dialog.show() sys.exit(app.exec_()) ================================================ FILE: Chapter01/demoCheckBox2.py ================================================ # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'demoCheckbox2.ui' # # Created by: PyQt5 UI code generator 5.6 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(646, 537) self.label = QtWidgets.QLabel(Dialog) self.label.setGeometry(QtCore.QRect(250, 0, 71, 31)) font = QtGui.QFont() font.setPointSize(14) self.label.setFont(font) self.label.setObjectName("label") self.label_2 = QtWidgets.QLabel(Dialog) self.label_2.setGeometry(QtCore.QRect(20, 80, 181, 31)) font = QtGui.QFont() font.setPointSize(14) self.label_2.setFont(font) self.label_2.setObjectName("label_2") self.labelDrinks = QtWidgets.QLabel(Dialog) self.labelDrinks.setGeometry(QtCore.QRect(40, 290, 151, 20)) font = QtGui.QFont() font.setPointSize(14) self.labelDrinks.setFont(font) self.labelDrinks.setObjectName("labelDrinks") self.groupBoxIceCreams = QtWidgets.QGroupBox(Dialog) self.groupBoxIceCreams.setGeometry(QtCore.QRect(230, 60, 241, 181)) self.groupBoxIceCreams.setCheckable(True) self.groupBoxIceCreams.setObjectName("groupBoxIceCreams") self.layoutWidget = QtWidgets.QWidget(self.groupBoxIceCreams) self.layoutWidget.setGeometry(QtCore.QRect(10, 30, 221, 62)) self.layoutWidget.setObjectName("layoutWidget") self.verticalLayout_3 = QtWidgets.QVBoxLayout(self.layoutWidget) self.verticalLayout_3.setContentsMargins(0, 0, 0, 0) self.verticalLayout_3.setObjectName("verticalLayout_3") self.checkBoxChoclateChips = QtWidgets.QCheckBox(self.layoutWidget) font = QtGui.QFont() font.setPointSize(14) self.checkBoxChoclateChips.setFont(font) self.checkBoxChoclateChips.setObjectName("checkBoxChoclateChips") self.verticalLayout_3.addWidget(self.checkBoxChoclateChips) self.checkBoxCookieDough = QtWidgets.QCheckBox(self.layoutWidget) font = QtGui.QFont() font.setPointSize(14) self.checkBoxCookieDough.setFont(font) self.checkBoxCookieDough.setObjectName("checkBoxCookieDough") self.verticalLayout_3.addWidget(self.checkBoxCookieDough) self.layoutWidget1 = QtWidgets.QWidget(self.groupBoxIceCreams) self.layoutWidget1.setGeometry(QtCore.QRect(10, 100, 213, 62)) self.layoutWidget1.setObjectName("layoutWidget1") self.verticalLayout_4 = QtWidgets.QVBoxLayout(self.layoutWidget1) self.verticalLayout_4.setContentsMargins(0, 0, 0, 0) self.verticalLayout_4.setObjectName("verticalLayout_4") self.checkBoxChoclateAlmond = QtWidgets.QCheckBox(self.layoutWidget1) font = QtGui.QFont() font.setPointSize(14) self.checkBoxChoclateAlmond.setFont(font) self.checkBoxChoclateAlmond.setObjectName("checkBoxChoclateAlmond") self.verticalLayout_4.addWidget(self.checkBoxChoclateAlmond) self.checkBoxRockyRoad = QtWidgets.QCheckBox(self.layoutWidget1) font = QtGui.QFont() font.setPointSize(14) self.checkBoxRockyRoad.setFont(font) self.checkBoxRockyRoad.setObjectName("checkBoxRockyRoad") self.verticalLayout_4.addWidget(self.checkBoxRockyRoad) self.groupBoxDrinks = QtWidgets.QGroupBox(Dialog) self.groupBoxDrinks.setGeometry(QtCore.QRect(230, 280, 181, 151)) self.groupBoxDrinks.setCheckable(True) self.groupBoxDrinks.setObjectName("groupBoxDrinks") self.layoutWidget2 = QtWidgets.QWidget(self.groupBoxDrinks) self.layoutWidget2.setGeometry(QtCore.QRect(10, 30, 110, 95)) self.layoutWidget2.setObjectName("layoutWidget2") self.verticalLayout = QtWidgets.QVBoxLayout(self.layoutWidget2) self.verticalLayout.setContentsMargins(0, 0, 0, 0) self.verticalLayout.setObjectName("verticalLayout") self.checkBoxCoffee = QtWidgets.QCheckBox(self.layoutWidget2) font = QtGui.QFont() font.setPointSize(14) self.checkBoxCoffee.setFont(font) self.checkBoxCoffee.setObjectName("checkBoxCoffee") self.verticalLayout.addWidget(self.checkBoxCoffee) self.checkBoxSoda = QtWidgets.QCheckBox(self.layoutWidget2) font = QtGui.QFont() font.setPointSize(14) self.checkBoxSoda.setFont(font) self.checkBoxSoda.setObjectName("checkBoxSoda") self.verticalLayout.addWidget(self.checkBoxSoda) self.checkBoxTea = QtWidgets.QCheckBox(self.layoutWidget2) font = QtGui.QFont() font.setPointSize(14) self.checkBoxTea.setFont(font) self.checkBoxTea.setObjectName("checkBoxTea") self.verticalLayout.addWidget(self.checkBoxTea) self.labelAmount = QtWidgets.QLabel(Dialog) self.labelAmount.setGeometry(QtCore.QRect(60, 450, 541, 31)) font = QtGui.QFont() font.setPointSize(14) self.labelAmount.setFont(font) self.labelAmount.setText("") self.labelAmount.setObjectName("labelAmount") self.groupBoxIceCreams.raise_() self.groupBoxDrinks.raise_() self.label.raise_() self.label_2.raise_() self.labelDrinks.raise_() self.labelAmount.raise_() 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", "Menu")) self.label_2.setText(_translate("Dialog", "Select your IceCream")) self.labelDrinks.setText(_translate("Dialog", "Select your drink")) self.groupBoxIceCreams.setTitle(_translate("Dialog", "IceCreams")) self.checkBoxChoclateChips.setText(_translate("Dialog", "Mint Choclate Chips $4")) self.checkBoxCookieDough.setText(_translate("Dialog", "Cookie Dough $2")) self.checkBoxChoclateAlmond.setText(_translate("Dialog", "Chocolate Almond $3")) self.checkBoxRockyRoad.setText(_translate("Dialog", "Rocky Road $5")) self.groupBoxDrinks.setTitle(_translate("Dialog", "Drinks")) self.checkBoxCoffee.setText(_translate("Dialog", "Coffee $2")) self.checkBoxSoda.setText(_translate("Dialog", "Soda $3")) self.checkBoxTea.setText(_translate("Dialog", "Tea $1")) ================================================ FILE: Chapter01/demoCheckbox1.ui ================================================ Dialog 0 0 503 272 Dialog 130 0 221 31 14 Regular Pizza $10 20 50 251 31 14 Select your extra toppings 270 60 191 17 14 Extra Cheese $1 270 90 241 21 14 Extra Olives $1 270 120 231 17 14 Extra Sausages $2 50 190 371 20 14 TextLabel ================================================ FILE: Chapter01/demoCheckbox2.ui ================================================ Dialog 0 0 646 537 Dialog 250 0 71 31 14 Menu 20 80 181 31 14 Select your IceCream 40 290 151 20 14 Select your drink 230 60 241 181 IceCreams true 10 30 221 62 14 Mint Choclate Chips $4 14 Cookie Dough $2 10 100 213 62 14 Chocolate Almond $3 14 Rocky Road $5 230 280 181 151 Drinks true 10 30 110 95 14 Coffee $2 14 Soda $3 14 Tea $1 60 450 541 31 14 groupBoxIceCreams groupBoxDrinks label label_2 labelDrinks labelAmount ================================================ FILE: Chapter01/demoLineEdit.py ================================================ # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'demoLineEdit.ui' # # Created by: PyQt5 UI code generator 5.6 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(379, 195) self.label = QtWidgets.QLabel(Dialog) self.label.setGeometry(QtCore.QRect(6, 40, 121, 20)) font = QtGui.QFont() font.setPointSize(11) self.label.setFont(font) self.label.setObjectName("label") self.labelResponse = QtWidgets.QLabel(Dialog) self.labelResponse.setGeometry(QtCore.QRect(40, 90, 271, 20)) font = QtGui.QFont() font.setPointSize(11) self.labelResponse.setFont(font) self.labelResponse.setObjectName("labelResponse") self.lineEditName = QtWidgets.QLineEdit(Dialog) self.lineEditName.setGeometry(QtCore.QRect(140, 40, 201, 20)) font = QtGui.QFont() font.setPointSize(11) self.lineEditName.setFont(font) self.lineEditName.setObjectName("lineEditName") self.ButtonClickMe = QtWidgets.QPushButton(Dialog) self.ButtonClickMe.setGeometry(QtCore.QRect(160, 130, 101, 23)) font = QtGui.QFont() font.setPointSize(11) self.ButtonClickMe.setFont(font) self.ButtonClickMe.setObjectName("ButtonClickMe") 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", "Enter your name")) self.labelResponse.setText(_translate("Dialog", "TextLabel")) self.ButtonClickMe.setText(_translate("Dialog", "Click")) ================================================ FILE: Chapter01/demoLineEdit.ui ================================================ Dialog 0 0 379 195 Dialog 6 40 121 20 11 Enter your name 40 90 271 20 11 TextLabel 140 40 201 20 11 160 130 101 23 11 Click ================================================ FILE: Chapter01/demoRadioButton1.py ================================================ # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'demoRadioButton1.ui' # # Created by: PyQt5 UI code generator 5.6 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(470, 290) self.radioButtonBusinessClass = QtWidgets.QRadioButton(Dialog) self.radioButtonBusinessClass.setGeometry(QtCore.QRect(30, 130, 251, 17)) font = QtGui.QFont() font.setPointSize(14) self.radioButtonBusinessClass.setFont(font) self.radioButtonBusinessClass.setObjectName("radioButtonBusinessClass") self.radioButtonEconomyClass = QtWidgets.QRadioButton(Dialog) self.radioButtonEconomyClass.setGeometry(QtCore.QRect(30, 180, 221, 31)) font = QtGui.QFont() font.setPointSize(14) self.radioButtonEconomyClass.setFont(font) self.radioButtonEconomyClass.setObjectName("radioButtonEconomyClass") self.radioButtonFirstClass = QtWidgets.QRadioButton(Dialog) self.radioButtonFirstClass.setGeometry(QtCore.QRect(30, 80, 201, 17)) font = QtGui.QFont() font.setPointSize(14) self.radioButtonFirstClass.setFont(font) self.radioButtonFirstClass.setObjectName("radioButtonFirstClass") self.label = QtWidgets.QLabel(Dialog) self.label.setGeometry(QtCore.QRect(80, 10, 261, 31)) font = QtGui.QFont() font.setPointSize(14) self.label.setFont(font) self.label.setObjectName("label") self.labelFare = QtWidgets.QLabel(Dialog) self.labelFare.setGeometry(QtCore.QRect(40, 245, 391, 21)) font = QtGui.QFont() font.setPointSize(14) self.labelFare.setFont(font) self.labelFare.setText("") self.labelFare.setObjectName("labelFare") self.retranslateUi(Dialog) QtCore.QMetaObject.connectSlotsByName(Dialog) def retranslateUi(self, Dialog): _translate = QtCore.QCoreApplication.translate Dialog.setWindowTitle(_translate("Dialog", "Dialog")) self.radioButtonBusinessClass.setText(_translate("Dialog", "Business Class $125")) self.radioButtonEconomyClass.setText(_translate("Dialog", "Economy Class $100")) self.radioButtonFirstClass.setText(_translate("Dialog", "First Class $150")) self.label.setText(_translate("Dialog", "Choose the flight type")) if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) Dialog = QtWidgets.QDialog() ui = Ui_Dialog() ui.setupUi(Dialog) Dialog.show() sys.exit(app.exec_()) ================================================ FILE: Chapter01/demoRadioButton1.ui ================================================ Dialog 0 0 470 290 Dialog 30 130 251 17 14 Business Class $125 30 180 221 31 14 Economy Class $100 30 80 201 17 14 First Class $150 80 10 261 31 14 Choose the flight type 40 245 391 21 14 ================================================ FILE: Chapter01/demoRadioButton2.py ================================================ # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'demoRadioButton2.ui' # # Created by: PyQt5 UI code generator 5.6 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(730, 452) self.label = QtWidgets.QLabel(Dialog) self.label.setGeometry(QtCore.QRect(100, 10, 221, 21)) font = QtGui.QFont() font.setPointSize(14) self.label.setFont(font) self.label.setObjectName("label") self.label_2 = QtWidgets.QLabel(Dialog) self.label_2.setGeometry(QtCore.QRect(100, 210, 261, 41)) font = QtGui.QFont() font.setPointSize(14) self.label_2.setFont(font) self.label_2.setObjectName("label_2") self.labelSelected = QtWidgets.QLabel(Dialog) self.labelSelected.setGeometry(QtCore.QRect(20, 380, 691, 41)) font = QtGui.QFont() font.setPointSize(14) self.labelSelected.setFont(font) self.labelSelected.setText("") self.labelSelected.setObjectName("labelSelected") self.layoutWidget = QtWidgets.QWidget(Dialog) self.layoutWidget.setGeometry(QtCore.QRect(100, 50, 56, 128)) self.layoutWidget.setObjectName("layoutWidget") self.verticalLayout = QtWidgets.QVBoxLayout(self.layoutWidget) self.verticalLayout.setContentsMargins(0, 0, 0, 0) self.verticalLayout.setObjectName("verticalLayout") self.radioButtonMedium = QtWidgets.QRadioButton(self.layoutWidget) font = QtGui.QFont() font.setPointSize(14) self.radioButtonMedium.setFont(font) self.radioButtonMedium.setObjectName("radioButtonMedium") self.verticalLayout.addWidget(self.radioButtonMedium) self.radioButtonLarge = QtWidgets.QRadioButton(self.layoutWidget) font = QtGui.QFont() font.setPointSize(14) self.radioButtonLarge.setFont(font) self.radioButtonLarge.setObjectName("radioButtonLarge") self.verticalLayout.addWidget(self.radioButtonLarge) self.radioButtonXL = QtWidgets.QRadioButton(self.layoutWidget) font = QtGui.QFont() font.setPointSize(14) self.radioButtonXL.setFont(font) self.radioButtonXL.setObjectName("radioButtonXL") self.verticalLayout.addWidget(self.radioButtonXL) self.radioButtonXXL = QtWidgets.QRadioButton(self.layoutWidget) font = QtGui.QFont() font.setPointSize(14) self.radioButtonXXL.setFont(font) self.radioButtonXXL.setObjectName("radioButtonXXL") self.verticalLayout.addWidget(self.radioButtonXXL) self.layoutWidget1 = QtWidgets.QWidget(Dialog) self.layoutWidget1.setGeometry(QtCore.QRect(100, 260, 170, 95)) self.layoutWidget1.setObjectName("layoutWidget1") self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.layoutWidget1) self.verticalLayout_2.setContentsMargins(0, 0, 0, 0) self.verticalLayout_2.setObjectName("verticalLayout_2") self.radioButtonDebitCard = QtWidgets.QRadioButton(self.layoutWidget1) font = QtGui.QFont() font.setPointSize(14) self.radioButtonDebitCard.setFont(font) self.radioButtonDebitCard.setObjectName("radioButtonDebitCard") self.verticalLayout_2.addWidget(self.radioButtonDebitCard) self.radioButtonNetBanking = QtWidgets.QRadioButton(self.layoutWidget1) font = QtGui.QFont() font.setPointSize(14) self.radioButtonNetBanking.setFont(font) self.radioButtonNetBanking.setObjectName("radioButtonNetBanking") self.verticalLayout_2.addWidget(self.radioButtonNetBanking) self.radioButtonCashOnDelivery = QtWidgets.QRadioButton(self.layoutWidget1) font = QtGui.QFont() font.setPointSize(14) self.radioButtonCashOnDelivery.setFont(font) self.radioButtonCashOnDelivery.setObjectName("radioButtonCashOnDelivery") self.verticalLayout_2.addWidget(self.radioButtonCashOnDelivery) 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", "Choose your Shirt Size")) self.label_2.setText(_translate("Dialog", "Choose your payment method")) self.radioButtonMedium.setText(_translate("Dialog", "M")) self.radioButtonLarge.setText(_translate("Dialog", "L")) self.radioButtonXL.setText(_translate("Dialog", "XL")) self.radioButtonXXL.setText(_translate("Dialog", "XXL")) self.radioButtonDebitCard.setText(_translate("Dialog", "Debit/Credit Card")) self.radioButtonNetBanking.setText(_translate("Dialog", "NetBanking")) self.radioButtonCashOnDelivery.setText(_translate("Dialog", "Cash On Delivery")) ================================================ FILE: Chapter01/demoRadioButton2.ui ================================================ Dialog 0 0 730 452 Dialog 100 10 221 21 14 Choose your Shirt Size 100 210 261 41 14 Choose your payment method 20 380 691 41 14 100 50 56 128 14 M 14 L 14 XL 14 XXL 100 260 170 95 14 Debit/Credit Card 14 NetBanking 14 Cash On Delivery ================================================ FILE: Chapter02/callCalculator.pyw ================================================ import sys from PyQt5.QtWidgets import QDialog, QApplication from demoCalculator import * class MyForm(QDialog): def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.ui.pushButtonPlus.clicked.connect(self.addtwonum) self.ui.pushButtonSubtract.clicked.connect(self.subtracttwonum) self.ui.pushButtonMultiply.clicked.connect(self.multiplytwonum) self.ui.pushButtonDivide.clicked.connect(self.dividetwonum) self.show() def addtwonum(self): if len(self.ui.lineEditFirstNumber.text())!=0: a=int(self.ui.lineEditFirstNumber.text()) else: a=0 if len(self.ui.lineEditSecondNumber.text())!=0: b=int(self.ui.lineEditSecondNumber.text()) else: b=0 sum=a+b self.ui.labelResult.setText("Addition: " +str(sum)) def subtracttwonum(self): if len(self.ui.lineEditFirstNumber.text())!=0: a=int(self.ui.lineEditFirstNumber.text()) else: a=0 if len(self.ui.lineEditSecondNumber.text())!=0: b=int(self.ui.lineEditSecondNumber.text()) else: b=0 diff=a-b self.ui.labelResult.setText("Substraction: " +str(diff)) def multiplytwonum(self): if len(self.ui.lineEditFirstNumber.text())!=0: a=int(self.ui.lineEditFirstNumber.text()) else: a=0 if len(self.ui.lineEditSecondNumber.text())!=0: b=int(self.ui.lineEditSecondNumber.text()) else: b=0 mult=a*b self.ui.labelResult.setText("Multiplication: " +str(mult)) def dividetwonum(self): if len(self.ui.lineEditFirstNumber.text())!=0: a=int(self.ui.lineEditFirstNumber.text()) else: a=0 if len(self.ui.lineEditSecondNumber.text())!=0: b=int(self.ui.lineEditSecondNumber.text()) else: b=0 division=a/b self.ui.labelResult.setText("Division: " +str(round(division,2))) if __name__=="__main__": app = QApplication(sys.argv) w = MyForm() w.show() sys.exit(app.exec_()) ================================================ FILE: Chapter02/callComboBox.pyw ================================================ import sys from PyQt5.QtWidgets import QDialog, QApplication from demoComboBox import * class MyForm(QDialog): def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.ui.comboBoxAccountType.currentIndexChanged.connect(self.dispAccountType) self.show() def dispAccountType(self): self.ui.labelAccountType.setText("You have selected "+self.ui.comboBoxAccountType.itemText(self.ui.comboBoxAccountType.currentIndex())) if __name__=="__main__": app = QApplication(sys.argv) w = MyForm() w.show() sys.exit(app.exec_()) ================================================ FILE: Chapter02/callFontComboBox.pyw ================================================ import sys from PyQt5.QtWidgets import QDialog, QApplication from demoFontComboBox import * class MyForm(QDialog): def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) myFont=QtGui.QFont(self.ui.fontComboBox.itemText(self.ui.fontComboBox.currentIndex()),15) self.ui.textEdit.setFont(myFont) self.ui.fontComboBox.currentFontChanged.connect(self.changeFont) self.show() def changeFont(self): myFont=QtGui.QFont(self.ui.fontComboBox.itemText(self.ui.fontComboBox.currentIndex()),15) self.ui.textEdit.setFont(myFont) if __name__=="__main__": app = QApplication(sys.argv) w = MyForm() w.show() sys.exit(app.exec_()) ================================================ FILE: Chapter02/callListWidget1.pyw ================================================ import sys from PyQt5.QtWidgets import QDialog, QApplication from demoListWidget1 import * class MyForm(QDialog): def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.ui.listWidgetDiagnosis.itemClicked.connect(self.dispSelectedTest) self.show() def dispSelectedTest(self): self.ui.labelTest.setText("You have selected "+self.ui.listWidgetDiagnosis.currentItem().text()) if __name__=="__main__": app = QApplication(sys.argv) w = MyForm() w.show() sys.exit(app.exec_()) ================================================ FILE: Chapter02/callListWidget2.pyw ================================================ import sys from PyQt5.QtWidgets import QDialog, QApplication from demoListWidget2 import * class MyForm(QDialog): def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.ui.listWidgetDiagnosis.itemSelectionChanged.connect(self.dispSelectedTest) self.show() def dispSelectedTest(self): self.ui.listWidgetSelectedTests.clear() items = self.ui.listWidgetDiagnosis.selectedItems() x=[] for i in list(items): self.ui.listWidgetSelectedTests.addItem(i.text()) x.append(str(i.text())) if __name__=="__main__": app = QApplication(sys.argv) w = MyForm() w.show() sys.exit(app.exec_()) ================================================ FILE: Chapter02/callListWidget3.pyw ================================================ import sys from PyQt5.QtWidgets import QDialog, QApplication from demoListWidget3 import * class MyForm(QDialog): def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.ui.pushButtonAdd.clicked.connect(self.addlist) self.show() def addlist(self): self.ui.listWidgetSelectedItems.addItem(self.ui.lineEditFoodItem.text()) self.ui.lineEditFoodItem.setText('') self.ui.lineEditFoodItem.setFocus() if __name__=="__main__": app = QApplication(sys.argv) w = MyForm() w.show() sys.exit(app.exec_()) ================================================ FILE: Chapter02/callListWidgetOp.pyw ================================================ import sys from PyQt5.QtWidgets import QDialog, QApplication, QInputDialog, QListWidgetItem from demoListWidgetOp import * class MyForm(QDialog): def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.ui.listWidget.addItem('Ice Cream') self.ui.listWidget.addItem('Soda') self.ui.listWidget.addItem('Coffee') self.ui.listWidget.addItem('Chocolate') self.ui.pushButtonAdd.clicked.connect(self.addlist) self.ui.pushButtonEdit.clicked.connect(self.editlist) self.ui.pushButtonDelete.clicked.connect(self.delitem) self.ui.pushButtonDeleteAll.clicked.connect(self.delallitems) self.show() def addlist(self): self.ui.listWidget.addItem(self.ui.lineEdit.text()) self.ui.lineEdit.setText('') self.ui.lineEdit.setFocus() def editlist(self): row=self.ui.listWidget.currentRow() newtext, ok=QInputDialog.getText(self, "Enter new text", "Enter new text") if ok and (len(newtext) !=0): self.ui.listWidget.takeItem(self.ui.listWidget.currentRow()) self.ui.listWidget.insertItem(row,QListWidgetItem(newtext)) def delitem(self): self.ui.listWidget.takeItem(self.ui.listWidget.currentRow()) def delallitems(self): self.ui.listWidget.clear() if __name__=="__main__": app = QApplication(sys.argv) w = MyForm() w.show() sys.exit(app.exec_()) ================================================ FILE: Chapter02/callProgressBar.pyw ================================================ import sys from PyQt5.QtWidgets import QDialog, QApplication from demoProgressBar import * class MyForm(QDialog): def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.ui.pushButtonStart.clicked.connect(self.updateBar) self.show() def updateBar(self): x = 0 while x < 100: x += 0.0001 self.ui.progressBar.setValue(x) if __name__=="__main__": app = QApplication(sys.argv) w = MyForm() w.show() sys.exit(app.exec_()) ================================================ FILE: Chapter02/callScrollBar.pyw ================================================ import sys from PyQt5.QtWidgets import QDialog, QApplication from demoScrollBar import * class MyForm(QDialog): def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.ui.horizontalScrollBarSugarLevel.valueChanged.connect(self.scrollhorizontal) self.ui.verticalScrollBarPulseRate.valueChanged.connect(self.scrollvertical) self.ui.horizontalSliderBloodPressure.valueChanged.connect(self.sliderhorizontal) self.ui.verticalSliderCholestrolLevel.valueChanged.connect(self.slidervertical) self.show() def scrollhorizontal(self,value): self.ui.lineEditResult.setText("Sugar Level : "+str(value)) def scrollvertical(self, value): self.ui.lineEditResult.setText("Pulse Rate : "+str(value)) def sliderhorizontal(self, value): self.ui.lineEditResult.setText("Blood Pressure : "+str(value)) def slidervertical(self, value): self.ui.lineEditResult.setText("Cholestrol Level : "+str(value)) if __name__=="__main__": app = QApplication(sys.argv) w = MyForm() w.show() sys.exit(app.exec_()) ================================================ FILE: Chapter02/calldemoSignalSlot1.pyw ================================================ import sys from PyQt5.QtWidgets import QDialog, QApplication from demoSignalSlot1 import * class MyForm(QDialog): def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.show() if __name__=="__main__": app = QApplication(sys.argv) w = MyForm() w.show() sys.exit(app.exec_()) ================================================ FILE: Chapter02/calldemoSpinner.pyw ================================================ import sys from PyQt5.QtWidgets import QDialog, QApplication from demoSpinBox import * class MyForm(QDialog): def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.ui.spinBoxBookQty.editingFinished.connect(self.result1) self.ui.doubleSpinBoxSugarWeight.editingFinished.connect(self.result2) self.show() def result1(self): if len(self.ui.lineEditBookPrice.text())!=0: bookPrice=int(self.ui.lineEditBookPrice.text()) else: bookPrice=0 totalBookAmount=self.ui.spinBoxBookQty.value() * bookPrice self.ui.lineEditBookAmount.setText(str(totalBookAmount)) def result2(self): if len(self.ui.lineEditSugarPrice.text())!=0: sugarPrice=float(self.ui.lineEditSugarPrice.text()) else: sugarPrice=0 totalSugarAmount=self.ui.doubleSpinBoxSugarWeight.value() * sugarPrice self.ui.lineEditSugarAmount.setText(str(round(totalSugarAmount,2))) totalBookAmount=int(self.ui.lineEditBookAmount.text()) totalAmount=totalBookAmount+totalSugarAmount self.ui.labelTotalAmount.setText(str(round(totalAmount,2))) if __name__=="__main__": app = QApplication(sys.argv) w = MyForm() w.show() sys.exit(app.exec_()) ================================================ FILE: Chapter02/demoCalculator.py ================================================ # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'demoCalculator.ui' # # Created by: PyQt5 UI code generator 5.6 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(427, 269) self.label = QtWidgets.QLabel(Dialog) self.label.setGeometry(QtCore.QRect(10, 30, 161, 20)) font = QtGui.QFont() font.setPointSize(12) self.label.setFont(font) self.label.setObjectName("label") self.label_2 = QtWidgets.QLabel(Dialog) self.label_2.setGeometry(QtCore.QRect(10, 80, 151, 20)) font = QtGui.QFont() font.setPointSize(12) self.label_2.setFont(font) self.label_2.setObjectName("label_2") self.lineEditFirstNumber = QtWidgets.QLineEdit(Dialog) self.lineEditFirstNumber.setGeometry(QtCore.QRect(180, 30, 181, 20)) font = QtGui.QFont() font.setPointSize(12) self.lineEditFirstNumber.setFont(font) self.lineEditFirstNumber.setObjectName("lineEditFirstNumber") self.lineEditSecondNumber = QtWidgets.QLineEdit(Dialog) self.lineEditSecondNumber.setGeometry(QtCore.QRect(180, 80, 181, 21)) font = QtGui.QFont() font.setPointSize(12) self.lineEditSecondNumber.setFont(font) self.lineEditSecondNumber.setObjectName("lineEditSecondNumber") self.pushButtonPlus = QtWidgets.QPushButton(Dialog) self.pushButtonPlus.setGeometry(QtCore.QRect(20, 150, 71, 31)) font = QtGui.QFont() font.setPointSize(12) self.pushButtonPlus.setFont(font) self.pushButtonPlus.setObjectName("pushButtonPlus") self.pushButtonSubtract = QtWidgets.QPushButton(Dialog) self.pushButtonSubtract.setGeometry(QtCore.QRect(120, 150, 75, 31)) font = QtGui.QFont() font.setPointSize(12) self.pushButtonSubtract.setFont(font) self.pushButtonSubtract.setObjectName("pushButtonSubtract") self.pushButtonMultiply = QtWidgets.QPushButton(Dialog) self.pushButtonMultiply.setGeometry(QtCore.QRect(220, 150, 81, 31)) font = QtGui.QFont() font.setPointSize(12) self.pushButtonMultiply.setFont(font) self.pushButtonMultiply.setObjectName("pushButtonMultiply") self.pushButtonDivide = QtWidgets.QPushButton(Dialog) self.pushButtonDivide.setGeometry(QtCore.QRect(330, 150, 75, 31)) font = QtGui.QFont() font.setPointSize(12) self.pushButtonDivide.setFont(font) self.pushButtonDivide.setObjectName("pushButtonDivide") self.labelResult = QtWidgets.QLabel(Dialog) self.labelResult.setGeometry(QtCore.QRect(30, 210, 351, 16)) font = QtGui.QFont() font.setPointSize(12) self.labelResult.setFont(font) self.labelResult.setText("") self.labelResult.setObjectName("labelResult") 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", "Enter first number")) self.label_2.setText(_translate("Dialog", "Enter second number")) self.pushButtonPlus.setText(_translate("Dialog", "+")) self.pushButtonSubtract.setText(_translate("Dialog", "-")) self.pushButtonMultiply.setText(_translate("Dialog", "X")) self.pushButtonDivide.setText(_translate("Dialog", "/")) ================================================ FILE: Chapter02/demoCalculator.ui ================================================ Dialog 0 0 427 269 Dialog 10 30 161 20 12 Enter first number 10 80 151 20 12 Enter second number 180 30 181 20 12 180 80 181 21 12 20 150 71 31 12 + 120 150 75 31 12 - 220 150 81 31 12 X 330 150 75 31 12 / 30 210 351 16 12 ================================================ FILE: Chapter02/demoComboBox.py ================================================ # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'demoComboBox.ui' # # Created by: PyQt5 UI code generator 5.6 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(674, 200) self.comboBoxAccountType = QtWidgets.QComboBox(Dialog) self.comboBoxAccountType.setGeometry(QtCore.QRect(260, 40, 361, 31)) font = QtGui.QFont() font.setPointSize(14) self.comboBoxAccountType.setFont(font) self.comboBoxAccountType.setObjectName("comboBoxAccountType") self.comboBoxAccountType.addItem("") self.comboBoxAccountType.addItem("") self.comboBoxAccountType.addItem("") self.comboBoxAccountType.addItem("") self.label = QtWidgets.QLabel(Dialog) self.label.setGeometry(QtCore.QRect(20, 40, 231, 31)) font = QtGui.QFont() font.setPointSize(14) self.label.setFont(font) self.label.setObjectName("label") self.labelAccountType = QtWidgets.QLabel(Dialog) self.labelAccountType.setGeometry(QtCore.QRect(40, 110, 581, 41)) font = QtGui.QFont() font.setPointSize(14) self.labelAccountType.setFont(font) self.labelAccountType.setText("") self.labelAccountType.setObjectName("labelAccountType") self.retranslateUi(Dialog) QtCore.QMetaObject.connectSlotsByName(Dialog) def retranslateUi(self, Dialog): _translate = QtCore.QCoreApplication.translate Dialog.setWindowTitle(_translate("Dialog", "Dialog")) self.comboBoxAccountType.setItemText(0, _translate("Dialog", "Saving Account")) self.comboBoxAccountType.setItemText(1, _translate("Dialog", "Current Account")) self.comboBoxAccountType.setItemText(2, _translate("Dialog", "Recurring Deposit Account")) self.comboBoxAccountType.setItemText(3, _translate("Dialog", "Fixed Deposit Account")) self.label.setText(_translate("Dialog", "Select your account type")) if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) Dialog = QtWidgets.QDialog() ui = Ui_Dialog() ui.setupUi(Dialog) Dialog.show() sys.exit(app.exec_()) ================================================ FILE: Chapter02/demoComboBox.ui ================================================ Dialog 0 0 674 200 Dialog 260 40 361 31 14 Saving Account Current Account Recurring Deposit Account Fixed Deposit Account 20 40 231 31 14 Select your account type 40 110 581 41 14 ================================================ FILE: Chapter02/demoFontComboBox.py ================================================ # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'demoFontComboBox.ui' # # Created by: PyQt5 UI code generator 5.6 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(560, 228) self.label = QtWidgets.QLabel(Dialog) self.label.setGeometry(QtCore.QRect(20, 20, 231, 41)) font = QtGui.QFont() font.setPointSize(14) self.label.setFont(font) self.label.setObjectName("label") self.labelTextLine = QtWidgets.QLabel(Dialog) self.labelTextLine.setGeometry(QtCore.QRect(20, 60, 161, 41)) font = QtGui.QFont() font.setPointSize(14) self.labelTextLine.setFont(font) self.labelTextLine.setObjectName("labelTextLine") self.fontComboBox = QtWidgets.QFontComboBox(Dialog) self.fontComboBox.setGeometry(QtCore.QRect(200, 20, 321, 31)) font = QtGui.QFont() font.setPointSize(14) self.fontComboBox.setFont(font) self.fontComboBox.setObjectName("fontComboBox") self.textEdit = QtWidgets.QTextEdit(Dialog) self.textEdit.setGeometry(QtCore.QRect(200, 70, 321, 121)) self.textEdit.setObjectName("textEdit") 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", "Select desired font")) self.labelTextLine.setText(_translate("Dialog", "Type some text")) if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) Dialog = QtWidgets.QDialog() ui = Ui_Dialog() ui.setupUi(Dialog) Dialog.show() sys.exit(app.exec_()) ================================================ FILE: Chapter02/demoFontComboBox.ui ================================================ Dialog 0 0 552 228 Dialog 20 20 231 41 14 Select desired font 20 60 161 41 14 Type some text 200 20 321 31 14 200 70 321 121 ================================================ FILE: Chapter02/demoListWidget1.py ================================================ # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'demoListWidget1.ui' # # Created by: PyQt5 UI code generator 5.6 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(686, 287) self.listWidgetDiagnosis = QtWidgets.QListWidget(Dialog) self.listWidgetDiagnosis.setGeometry(QtCore.QRect(280, 20, 351, 171)) font = QtGui.QFont() font.setPointSize(14) self.listWidgetDiagnosis.setFont(font) self.listWidgetDiagnosis.setObjectName("listWidgetDiagnosis") item = QtWidgets.QListWidgetItem() self.listWidgetDiagnosis.addItem(item) item = QtWidgets.QListWidgetItem() self.listWidgetDiagnosis.addItem(item) item = QtWidgets.QListWidgetItem() self.listWidgetDiagnosis.addItem(item) item = QtWidgets.QListWidgetItem() self.listWidgetDiagnosis.addItem(item) item = QtWidgets.QListWidgetItem() self.listWidgetDiagnosis.addItem(item) self.labelTest = QtWidgets.QLabel(Dialog) self.labelTest.setGeometry(QtCore.QRect(40, 230, 621, 31)) font = QtGui.QFont() font.setPointSize(14) self.labelTest.setFont(font) self.labelTest.setText("") self.labelTest.setObjectName("labelTest") self.label = QtWidgets.QLabel(Dialog) self.label.setGeometry(QtCore.QRect(30, 10, 241, 31)) font = QtGui.QFont() font.setPointSize(14) self.label.setFont(font) self.label.setObjectName("label") self.retranslateUi(Dialog) QtCore.QMetaObject.connectSlotsByName(Dialog) def retranslateUi(self, Dialog): _translate = QtCore.QCoreApplication.translate Dialog.setWindowTitle(_translate("Dialog", "Dialog")) __sortingEnabled = self.listWidgetDiagnosis.isSortingEnabled() self.listWidgetDiagnosis.setSortingEnabled(False) item = self.listWidgetDiagnosis.item(0) item.setText(_translate("Dialog", "Urine Analaysis $5")) item = self.listWidgetDiagnosis.item(1) item.setText(_translate("Dialog", "Chest X Ray 100$")) item = self.listWidgetDiagnosis.item(2) item.setText(_translate("Dialog", "Sugar Level test $3")) item = self.listWidgetDiagnosis.item(3) item.setText(_translate("Dialog", "Hemoglobin test $7")) item = self.listWidgetDiagnosis.item(4) item.setText(_translate("Dialog", "Thyroid Stimulating Harmone test $10")) self.listWidgetDiagnosis.setSortingEnabled(__sortingEnabled) self.label.setText(_translate("Dialog", "Choose the Diagnosis Tests")) ================================================ FILE: Chapter02/demoListWidget1.ui ================================================ Dialog 0 0 686 287 Dialog 280 20 351 171 14 Urine Analaysis $5 Chest X Ray 100$ Sugar Level test $3 Hemoglobin test $7 Thyroid Stimulating Harmone test $10 40 230 621 31 14 30 10 241 31 14 Choose the Diagnosis Tests ================================================ FILE: Chapter02/demoListWidget2.py ================================================ # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'demoListWidget2.ui' # # Created by: PyQt5 UI code generator 5.6 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(729, 412) self.listWidgetDiagnosis = QtWidgets.QListWidget(Dialog) self.listWidgetDiagnosis.setGeometry(QtCore.QRect(200, 20, 351, 171)) font = QtGui.QFont() font.setPointSize(14) self.listWidgetDiagnosis.setFont(font) self.listWidgetDiagnosis.setSelectionMode(QtWidgets.QAbstractItemView.MultiSelection) self.listWidgetDiagnosis.setObjectName("listWidgetDiagnosis") item = QtWidgets.QListWidgetItem() self.listWidgetDiagnosis.addItem(item) item = QtWidgets.QListWidgetItem() self.listWidgetDiagnosis.addItem(item) item = QtWidgets.QListWidgetItem() self.listWidgetDiagnosis.addItem(item) item = QtWidgets.QListWidgetItem() self.listWidgetDiagnosis.addItem(item) item = QtWidgets.QListWidgetItem() self.listWidgetDiagnosis.addItem(item) self.labelTest = QtWidgets.QLabel(Dialog) self.labelTest.setGeometry(QtCore.QRect(20, 230, 171, 31)) font = QtGui.QFont() font.setPointSize(14) self.labelTest.setFont(font) self.labelTest.setObjectName("labelTest") self.label = QtWidgets.QLabel(Dialog) self.label.setGeometry(QtCore.QRect(30, 10, 151, 31)) font = QtGui.QFont() font.setPointSize(14) self.label.setFont(font) self.label.setObjectName("label") self.listWidgetSelectedTests = QtWidgets.QListWidget(Dialog) self.listWidgetSelectedTests.setGeometry(QtCore.QRect(200, 220, 351, 192)) font = QtGui.QFont() font.setPointSize(14) self.listWidgetSelectedTests.setFont(font) self.listWidgetSelectedTests.setObjectName("listWidgetSelectedTests") self.retranslateUi(Dialog) QtCore.QMetaObject.connectSlotsByName(Dialog) def retranslateUi(self, Dialog): _translate = QtCore.QCoreApplication.translate Dialog.setWindowTitle(_translate("Dialog", "Dialog")) __sortingEnabled = self.listWidgetDiagnosis.isSortingEnabled() self.listWidgetDiagnosis.setSortingEnabled(False) item = self.listWidgetDiagnosis.item(0) item.setText(_translate("Dialog", "Urine Analaysis $5")) item = self.listWidgetDiagnosis.item(1) item.setText(_translate("Dialog", "Chest X Ray 100$")) item = self.listWidgetDiagnosis.item(2) item.setText(_translate("Dialog", "Sugar Level test $3")) item = self.listWidgetDiagnosis.item(3) item.setText(_translate("Dialog", "Hemoglobin test $7")) item = self.listWidgetDiagnosis.item(4) item.setText(_translate("Dialog", "Thyroid Stimulating Harmone test $10")) self.listWidgetDiagnosis.setSortingEnabled(__sortingEnabled) self.labelTest.setText(_translate("Dialog", "Selected tests are")) self.label.setText(_translate("Dialog", "Diagnosis Tests")) if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) Dialog = QtWidgets.QDialog() ui = Ui_Dialog() ui.setupUi(Dialog) Dialog.show() sys.exit(app.exec_()) ================================================ FILE: Chapter02/demoListWidget2.ui ================================================ Dialog 0 0 729 412 Dialog 200 20 351 171 14 QAbstractItemView::MultiSelection Urine Analaysis $5 Chest X Ray 100$ Sugar Level test $3 Hemoglobin test $7 Thyroid Stimulating Harmone test $10 20 230 171 31 14 Selected tests are 30 10 151 31 14 Diagnosis Tests 200 220 351 192 14 ================================================ FILE: Chapter02/demoListWidget3.py ================================================ # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'demoListWidget3.ui' # # Created by: PyQt5 UI code generator 5.6 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(734, 270) self.label = QtWidgets.QLabel(Dialog) self.label.setGeometry(QtCore.QRect(20, 20, 191, 16)) font = QtGui.QFont() font.setPointSize(12) self.label.setFont(font) self.label.setObjectName("label") self.lineEditFoodItem = QtWidgets.QLineEdit(Dialog) self.lineEditFoodItem.setGeometry(QtCore.QRect(210, 20, 201, 20)) font = QtGui.QFont() font.setPointSize(12) self.lineEditFoodItem.setFont(font) self.lineEditFoodItem.setObjectName("lineEditFoodItem") self.pushButtonAdd = QtWidgets.QPushButton(Dialog) self.pushButtonAdd.setGeometry(QtCore.QRect(110, 72, 111, 31)) font = QtGui.QFont() font.setPointSize(12) self.pushButtonAdd.setFont(font) self.pushButtonAdd.setObjectName("pushButtonAdd") self.listWidgetSelectedItems = QtWidgets.QListWidget(Dialog) self.listWidgetSelectedItems.setGeometry(QtCore.QRect(430, 20, 256, 221)) font = QtGui.QFont() font.setPointSize(12) self.listWidgetSelectedItems.setFont(font) self.listWidgetSelectedItems.setObjectName("listWidgetSelectedItems") 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", "Your favourite food item")) self.pushButtonAdd.setText(_translate("Dialog", "Add to List")) if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) Dialog = QtWidgets.QDialog() ui = Ui_Dialog() ui.setupUi(Dialog) Dialog.show() sys.exit(app.exec_()) ================================================ FILE: Chapter02/demoListWidget3.ui ================================================ Dialog 0 0 734 270 Dialog 20 20 191 16 12 Your favourite food item 210 20 201 20 12 110 72 111 31 12 Add to List 430 20 256 221 12 ================================================ FILE: Chapter02/demoListWidgetOp.py ================================================ # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'demoListWidgetOp.ui' # # Created by: PyQt5 UI code generator 5.6 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(691, 260) self.label = QtWidgets.QLabel(Dialog) self.label.setGeometry(QtCore.QRect(16, 30, 121, 20)) font = QtGui.QFont() font.setPointSize(12) self.label.setFont(font) self.label.setObjectName("label") self.lineEdit = QtWidgets.QLineEdit(Dialog) self.lineEdit.setGeometry(QtCore.QRect(130, 30, 191, 31)) font = QtGui.QFont() font.setPointSize(12) self.lineEdit.setFont(font) self.lineEdit.setObjectName("lineEdit") self.pushButtonAdd = QtWidgets.QPushButton(Dialog) self.pushButtonAdd.setGeometry(QtCore.QRect(180, 80, 75, 23)) font = QtGui.QFont() font.setPointSize(12) self.pushButtonAdd.setFont(font) self.pushButtonAdd.setObjectName("pushButtonAdd") self.listWidget = QtWidgets.QListWidget(Dialog) self.listWidget.setGeometry(QtCore.QRect(380, 30, 256, 192)) font = QtGui.QFont() font.setPointSize(12) self.listWidget.setFont(font) self.listWidget.setObjectName("listWidget") self.pushButtonDelete = QtWidgets.QPushButton(Dialog) self.pushButtonDelete.setGeometry(QtCore.QRect(470, 230, 75, 23)) font = QtGui.QFont() font.setPointSize(12) self.pushButtonDelete.setFont(font) self.pushButtonDelete.setObjectName("pushButtonDelete") self.pushButtonDeleteAll = QtWidgets.QPushButton(Dialog) self.pushButtonDeleteAll.setGeometry(QtCore.QRect(560, 230, 75, 23)) font = QtGui.QFont() font.setPointSize(12) self.pushButtonDeleteAll.setFont(font) self.pushButtonDeleteAll.setObjectName("pushButtonDeleteAll") self.pushButtonEdit = QtWidgets.QPushButton(Dialog) self.pushButtonEdit.setGeometry(QtCore.QRect(380, 230, 75, 23)) font = QtGui.QFont() font.setPointSize(12) self.pushButtonEdit.setFont(font) self.pushButtonEdit.setObjectName("pushButtonEdit") 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", "Enter an item")) self.pushButtonAdd.setText(_translate("Dialog", "Add")) self.pushButtonDelete.setText(_translate("Dialog", "Delete")) self.pushButtonDeleteAll.setText(_translate("Dialog", "Delete All")) self.pushButtonEdit.setText(_translate("Dialog", "Edit")) if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) Dialog = QtWidgets.QDialog() ui = Ui_Dialog() ui.setupUi(Dialog) Dialog.show() sys.exit(app.exec_()) ================================================ FILE: Chapter02/demoListWidgetOp.ui ================================================ Dialog 0 0 691 260 Dialog 16 30 121 20 12 Enter an item 130 30 191 31 12 180 80 75 23 12 Add 380 30 256 192 12 470 230 75 23 12 Delete 560 230 75 23 12 Delete All 380 230 75 23 12 Edit ================================================ FILE: Chapter02/demoProgressBar.py ================================================ # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'demoProgressBar.ui' # # Created by: PyQt5 UI code generator 5.6 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(350, 153) self.progressBar = QtWidgets.QProgressBar(Dialog) self.progressBar.setGeometry(QtCore.QRect(40, 60, 281, 23)) font = QtGui.QFont() font.setPointSize(12) self.progressBar.setFont(font) self.progressBar.setProperty("value", 0) self.progressBar.setObjectName("progressBar") self.label = QtWidgets.QLabel(Dialog) self.label.setGeometry(QtCore.QRect(80, 20, 181, 21)) font = QtGui.QFont() font.setPointSize(12) self.label.setFont(font) self.label.setObjectName("label") self.pushButtonStart = QtWidgets.QPushButton(Dialog) self.pushButtonStart.setGeometry(QtCore.QRect(80, 110, 151, 31)) font = QtGui.QFont() font.setPointSize(12) self.pushButtonStart.setFont(font) self.pushButtonStart.setObjectName("pushButtonStart") 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", "Downloading the file")) self.pushButtonStart.setText(_translate("Dialog", "Start Downloading")) if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) Dialog = QtWidgets.QDialog() ui = Ui_Dialog() ui.setupUi(Dialog) Dialog.show() sys.exit(app.exec_()) ================================================ FILE: Chapter02/demoProgressBar.ui ================================================ Dialog 0 0 350 153 Dialog 40 60 281 23 12 0 80 20 181 21 12 Downloading the file 80 110 151 31 12 Start Downloading ================================================ FILE: Chapter02/demoScrollBar.py ================================================ # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'demoScrollBar.ui' # # Created by: PyQt5 UI code generator 5.6 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(538, 431) self.horizontalScrollBarSugarLevel = QtWidgets.QScrollBar(Dialog) self.horizontalScrollBarSugarLevel.setGeometry(QtCore.QRect(200, 30, 301, 21)) font = QtGui.QFont() font.setPointSize(12) self.horizontalScrollBarSugarLevel.setFont(font) self.horizontalScrollBarSugarLevel.setOrientation(QtCore.Qt.Horizontal) self.horizontalScrollBarSugarLevel.setObjectName("horizontalScrollBarSugarLevel") self.label = QtWidgets.QLabel(Dialog) self.label.setGeometry(QtCore.QRect(40, 30, 111, 21)) font = QtGui.QFont() font.setPointSize(12) self.label.setFont(font) self.label.setObjectName("label") self.label_2 = QtWidgets.QLabel(Dialog) self.label_2.setGeometry(QtCore.QRect(40, 110, 141, 16)) font = QtGui.QFont() font.setPointSize(12) self.label_2.setFont(font) self.label_2.setObjectName("label_2") self.verticalScrollBarPulseRate = QtWidgets.QScrollBar(Dialog) self.verticalScrollBarPulseRate.setGeometry(QtCore.QRect(160, 110, 16, 160)) font = QtGui.QFont() font.setPointSize(12) self.verticalScrollBarPulseRate.setFont(font) self.verticalScrollBarPulseRate.setOrientation(QtCore.Qt.Vertical) self.verticalScrollBarPulseRate.setObjectName("verticalScrollBarPulseRate") self.label_3 = QtWidgets.QLabel(Dialog) self.label_3.setGeometry(QtCore.QRect(40, 70, 151, 16)) font = QtGui.QFont() font.setPointSize(12) self.label_3.setFont(font) self.label_3.setObjectName("label_3") self.horizontalSliderBloodPressure = QtWidgets.QSlider(Dialog) self.horizontalSliderBloodPressure.setGeometry(QtCore.QRect(210, 70, 291, 22)) font = QtGui.QFont() font.setPointSize(12) self.horizontalSliderBloodPressure.setFont(font) self.horizontalSliderBloodPressure.setOrientation(QtCore.Qt.Horizontal) self.horizontalSliderBloodPressure.setObjectName("horizontalSliderBloodPressure") self.label_4 = QtWidgets.QLabel(Dialog) self.label_4.setGeometry(QtCore.QRect(240, 110, 131, 16)) font = QtGui.QFont() font.setPointSize(12) self.label_4.setFont(font) self.label_4.setObjectName("label_4") self.verticalSliderCholestrolLevel = QtWidgets.QSlider(Dialog) self.verticalSliderCholestrolLevel.setGeometry(QtCore.QRect(410, 109, 22, 171)) font = QtGui.QFont() font.setPointSize(12) self.verticalSliderCholestrolLevel.setFont(font) self.verticalSliderCholestrolLevel.setOrientation(QtCore.Qt.Vertical) self.verticalSliderCholestrolLevel.setObjectName("verticalSliderCholestrolLevel") self.lineEditResult = QtWidgets.QLineEdit(Dialog) self.lineEditResult.setGeometry(QtCore.QRect(60, 340, 391, 31)) font = QtGui.QFont() font.setPointSize(12) self.lineEditResult.setFont(font) self.lineEditResult.setObjectName("lineEditResult") 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", "Sugar Level")) self.label_2.setText(_translate("Dialog", "Pulse rate")) self.label_3.setText(_translate("Dialog", "Blood Pressure")) self.label_4.setText(_translate("Dialog", "Cholestrol Level")) if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) Dialog = QtWidgets.QDialog() ui = Ui_Dialog() ui.setupUi(Dialog) Dialog.show() sys.exit(app.exec_()) ================================================ FILE: Chapter02/demoScrollBar.ui ================================================ Dialog 0 0 538 431 Dialog 200 30 301 21 12 Qt::Horizontal 40 30 111 21 12 Sugar Level 40 110 141 16 12 Pulse rate 160 110 16 160 12 Qt::Vertical 40 70 151 16 12 Blood Pressure 210 70 291 22 12 Qt::Horizontal 240 110 131 16 12 Cholestrol Level 410 109 22 171 12 Qt::Vertical 60 340 391 31 12 ================================================ FILE: Chapter02/demoSignalSlot1.py ================================================ # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'demoSignalSlot1.ui' # # Created by: PyQt5 UI code generator 5.6 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(348, 453) self.lineEdit = QtWidgets.QLineEdit(Dialog) self.lineEdit.setGeometry(QtCore.QRect(90, 50, 181, 20)) self.lineEdit.setObjectName("lineEdit") self.pushButton = QtWidgets.QPushButton(Dialog) self.pushButton.setGeometry(QtCore.QRect(140, 160, 75, 23)) self.pushButton.setObjectName("pushButton") self.pushButton_2 = QtWidgets.QPushButton(Dialog) self.pushButton_2.setGeometry(QtCore.QRect(140, 260, 75, 23)) self.pushButton_2.setObjectName("pushButton_2") self.lineEdit_2 = QtWidgets.QLineEdit(Dialog) self.lineEdit_2.setGeometry(QtCore.QRect(90, 390, 181, 20)) self.lineEdit_2.setObjectName("lineEdit_2") self.retranslateUi(Dialog) self.pushButton.pressed.connect(self.lineEdit.selectAll) self.pushButton_2.clicked.connect(self.lineEdit_2.paste) self.pushButton.released.connect(self.lineEdit.copy) QtCore.QMetaObject.connectSlotsByName(Dialog) def retranslateUi(self, Dialog): _translate = QtCore.QCoreApplication.translate Dialog.setWindowTitle(_translate("Dialog", "Dialog")) self.pushButton.setText(_translate("Dialog", "Copy")) self.pushButton_2.setText(_translate("Dialog", "Paste")) if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) Dialog = QtWidgets.QDialog() ui = Ui_Dialog() ui.setupUi(Dialog) Dialog.show() sys.exit(app.exec_()) ================================================ FILE: Chapter02/demoSignalSlot1.ui ================================================ Dialog 0 0 348 453 Dialog 90 50 181 20 140 160 75 23 Copy 140 260 75 23 Paste 90 390 181 20 pushButton pressed() lineEdit selectAll() 175 181 183 67 pushButton_2 clicked() lineEdit_2 paste() 174 277 172 396 pushButton released() lineEdit copy() 150 169 153 58 ================================================ FILE: Chapter02/demoSpinBox.py ================================================ # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'demoSpinBox.ui' # # Created by: PyQt5 UI code generator 5.6 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(580, 162) self.label = QtWidgets.QLabel(Dialog) self.label.setGeometry(QtCore.QRect(16, 30, 81, 20)) font = QtGui.QFont() font.setPointSize(12) self.label.setFont(font) self.label.setObjectName("label") self.lineEditBookPrice = QtWidgets.QLineEdit(Dialog) self.lineEditBookPrice.setGeometry(QtCore.QRect(120, 30, 113, 20)) font = QtGui.QFont() font.setPointSize(12) self.lineEditBookPrice.setFont(font) self.lineEditBookPrice.setObjectName("lineEditBookPrice") self.spinBoxBookQty = QtWidgets.QSpinBox(Dialog) self.spinBoxBookQty.setGeometry(QtCore.QRect(290, 30, 42, 22)) font = QtGui.QFont() font.setPointSize(12) self.spinBoxBookQty.setFont(font) self.spinBoxBookQty.setObjectName("spinBoxBookQty") self.lineEditBookAmount = QtWidgets.QLineEdit(Dialog) self.lineEditBookAmount.setGeometry(QtCore.QRect(390, 30, 113, 20)) font = QtGui.QFont() font.setPointSize(12) self.lineEditBookAmount.setFont(font) self.lineEditBookAmount.setObjectName("lineEditBookAmount") self.label_2 = QtWidgets.QLabel(Dialog) self.label_2.setGeometry(QtCore.QRect(10, 70, 81, 21)) font = QtGui.QFont() font.setPointSize(12) self.label_2.setFont(font) self.label_2.setObjectName("label_2") self.lineEditSugarPrice = QtWidgets.QLineEdit(Dialog) self.lineEditSugarPrice.setGeometry(QtCore.QRect(120, 70, 113, 20)) font = QtGui.QFont() font.setPointSize(12) self.lineEditSugarPrice.setFont(font) self.lineEditSugarPrice.setObjectName("lineEditSugarPrice") self.doubleSpinBoxSugarWeight = QtWidgets.QDoubleSpinBox(Dialog) self.doubleSpinBoxSugarWeight.setGeometry(QtCore.QRect(290, 70, 62, 22)) font = QtGui.QFont() font.setPointSize(12) self.doubleSpinBoxSugarWeight.setFont(font) self.doubleSpinBoxSugarWeight.setObjectName("doubleSpinBoxSugarWeight") self.lineEditSugarAmount = QtWidgets.QLineEdit(Dialog) self.lineEditSugarAmount.setGeometry(QtCore.QRect(390, 70, 113, 20)) font = QtGui.QFont() font.setPointSize(12) self.lineEditSugarAmount.setFont(font) self.lineEditSugarAmount.setObjectName("lineEditSugarAmount") self.labelTotalAmount = QtWidgets.QLabel(Dialog) self.labelTotalAmount.setGeometry(QtCore.QRect(396, 120, 121, 20)) font = QtGui.QFont() font.setPointSize(12) self.labelTotalAmount.setFont(font) self.labelTotalAmount.setObjectName("labelTotalAmount") 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", "Book Price")) self.label_2.setText(_translate("Dialog", "Sugar Price")) self.labelTotalAmount.setText(_translate("Dialog", "TextLabel")) ================================================ FILE: Chapter02/demoSpinBox.ui ================================================ Dialog 0 0 580 162 Dialog 16 30 81 20 12 Book Price 120 30 113 20 12 290 30 42 22 12 390 30 113 20 12 10 70 81 21 12 Sugar Price 120 70 113 20 12 290 70 62 22 12 390 70 113 20 12 396 120 121 20 12 ================================================ FILE: Chapter03/DemoTableWidget.ui ================================================ Dialog 0 0 289 236 Dialog 30 20 221 191 4 2 50 false 40 false ================================================ FILE: Chapter03/callCalendar.pyw ================================================ import sys from PyQt5.QtWidgets import QDialog, QApplication from demoCalendar import * class MyForm(QDialog): def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.ui.calendarWidget.selectionChanged.connect(self.dispdate) self.show() def dispdate(self): self.ui.dateEdit.setDisplayFormat('MMM d yyyy') self.ui.dateEdit.setDate(self.ui.calendarWidget.selectedDate()) if __name__=="__main__": app = QApplication(sys.argv) w = MyForm() w.show() sys.exit(app.exec_()) ================================================ FILE: Chapter03/callLCD.pyw ================================================ import sys from PyQt5.QtWidgets import QDialog, QApplication from demoLCD import * class MyForm(QDialog): def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) timer = QtCore.QTimer(self) timer.timeout.connect(self.showlcd) timer.start(1000) self.showlcd() def showlcd(self): time = QtCore.QTime.currentTime() text = time.toString('hh:mm') self.ui.lcdNumber.display(text) if __name__=="__main__": app = QApplication(sys.argv) w = MyForm() w.show() sys.exit(app.exec_()) ================================================ FILE: Chapter03/callTableWidget.pyw ================================================ import sys from PyQt5.QtWidgets import QDialog, QApplication,QTableWidgetItem from DemoTableWidget import * class MyForm(QDialog): def __init__(self,data): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.data=data self.addcontent() def addcontent(self): row=0 for tup in self.data: col=0 for item in tup: oneitem=QTableWidgetItem(item) self.ui.tableWidget.setItem(row, col, oneitem) col+=1 row+=1 data=[] data.append(('Suite', '40$')) data.append(('Super Luxury', '30$')) data.append(('Super Deluxe', '20$')) data.append(('Ordinary', '10$')) if __name__=="__main__": app = QApplication(sys.argv) w = MyForm(data) w.show() sys.exit(app.exec_()) ================================================ FILE: Chapter03/computeRoomRent.pyw ================================================ import sys from PyQt5.QtWidgets import QDialog, QApplication from reservehotel import * class MyForm(QDialog): def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.roomtypes=['Suite', 'Super Luxury', 'Super Deluxe', 'Ordinary'] self.addcontent() self.ui.pushButton.clicked.connect(self.computeRoomRent) self.show() def addcontent(self): for i in self.roomtypes: self.ui.comboBox.addItem(i) def computeRoomRent(self): dateselected=self.ui.calendarWidget.selectedDate() dateinstring=str(dateselected.toPyDate()) noOfDays=self.ui.spinBox.value() chosenRoomType=self.ui.comboBox.itemText(self.ui.comboBox.currentIndex()) self.ui.Enteredinfo.setText('Date of reservation: '+dateinstring+ ', Number of days: '+ str(noOfDays) + ' \nand Room type selected: '+ chosenRoomType) roomRent=0 if chosenRoomType=="Suite": roomRent=40 if chosenRoomType=="Super Luxury": roomRent=30 if chosenRoomType=="Super Deluxe": roomRent=20 if chosenRoomType=="Ordinary": roomRent=10 total=roomRent*noOfDays self.ui.RoomRentinfo.setText('Room Rent for single day for '+ chosenRoomType +' type is '+ str(roomRent)+ '$. \nTotal room rent is '+ str(total)+ '$') if __name__=="__main__": app = QApplication(sys.argv) w = MyForm() w.show() sys.exit(app.exec_()) ================================================ FILE: Chapter03/demoCalendar.py ================================================ # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'demoCalendar.ui' # # Created by: PyQt5 UI code generator 5.6 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(384, 300) self.calendarWidget = QtWidgets.QCalendarWidget(Dialog) self.calendarWidget.setGeometry(QtCore.QRect(40, 30, 312, 183)) self.calendarWidget.setObjectName("calendarWidget") self.dateEdit = QtWidgets.QDateEdit(Dialog) self.dateEdit.setGeometry(QtCore.QRect(120, 250, 110, 22)) self.dateEdit.setObjectName("dateEdit") self.retranslateUi(Dialog) QtCore.QMetaObject.connectSlotsByName(Dialog) def retranslateUi(self, Dialog): _translate = QtCore.QCoreApplication.translate Dialog.setWindowTitle(_translate("Dialog", "Dialog")) if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) Dialog = QtWidgets.QDialog() ui = Ui_Dialog() ui.setupUi(Dialog) Dialog.show() sys.exit(app.exec_()) ================================================ FILE: Chapter03/demoCalendar.ui ================================================ Dialog 0 0 384 300 Dialog 40 30 312 183 120 250 110 22 ================================================ FILE: Chapter03/demoLCD.py ================================================ # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'demoLCD.ui' # # Created by: PyQt5 UI code generator 5.6 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(240, 135) self.lcdNumber = QtWidgets.QLCDNumber(Dialog) self.lcdNumber.setGeometry(QtCore.QRect(60, 40, 100, 40)) self.lcdNumber.setObjectName("lcdNumber") self.retranslateUi(Dialog) QtCore.QMetaObject.connectSlotsByName(Dialog) def retranslateUi(self, Dialog): _translate = QtCore.QCoreApplication.translate Dialog.setWindowTitle(_translate("Dialog", "Dialog")) if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) Dialog = QtWidgets.QDialog() ui = Ui_Dialog() ui.setupUi(Dialog) Dialog.show() sys.exit(app.exec_()) ================================================ FILE: Chapter03/demoLCD.ui ================================================ Dialog 0 0 240 135 Dialog 60 40 100 40 ================================================ FILE: Chapter03/demoTabWidget.py ================================================ # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'demoTabWidget.ui' # # Created by: PyQt5 UI code generator 5.6 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(574, 300) self.tabWidget = QtWidgets.QTabWidget(Dialog) self.tabWidget.setGeometry(QtCore.QRect(10, 10, 481, 271)) font = QtGui.QFont() font.setPointSize(12) self.tabWidget.setFont(font) self.tabWidget.setObjectName("tabWidget") self.tab = QtWidgets.QWidget() self.tab.setObjectName("tab") self.checkBox = QtWidgets.QCheckBox(self.tab) self.checkBox.setGeometry(QtCore.QRect(30, 30, 191, 17)) self.checkBox.setObjectName("checkBox") self.checkBox_2 = QtWidgets.QCheckBox(self.tab) self.checkBox_2.setGeometry(QtCore.QRect(30, 70, 141, 17)) self.checkBox_2.setObjectName("checkBox_2") self.checkBox_3 = QtWidgets.QCheckBox(self.tab) self.checkBox_3.setGeometry(QtCore.QRect(30, 110, 161, 17)) self.checkBox_3.setObjectName("checkBox_3") self.checkBox_4 = QtWidgets.QCheckBox(self.tab) self.checkBox_4.setGeometry(QtCore.QRect(30, 150, 171, 17)) self.checkBox_4.setObjectName("checkBox_4") self.pushButton = QtWidgets.QPushButton(self.tab) self.pushButton.setGeometry(QtCore.QRect(40, 190, 141, 23)) self.pushButton.setObjectName("pushButton") self.tabWidget.addTab(self.tab, "") self.tab_2 = QtWidgets.QWidget() self.tab_2.setObjectName("tab_2") self.radioButton = QtWidgets.QRadioButton(self.tab_2) self.radioButton.setGeometry(QtCore.QRect(40, 30, 131, 17)) self.radioButton.setObjectName("radioButton") self.radioButton_2 = QtWidgets.QRadioButton(self.tab_2) self.radioButton_2.setGeometry(QtCore.QRect(40, 80, 111, 17)) self.radioButton_2.setObjectName("radioButton_2") self.radioButton_3 = QtWidgets.QRadioButton(self.tab_2) self.radioButton_3.setGeometry(QtCore.QRect(40, 130, 121, 21)) self.radioButton_3.setObjectName("radioButton_3") self.radioButton_4 = QtWidgets.QRadioButton(self.tab_2) self.radioButton_4.setGeometry(QtCore.QRect(40, 180, 181, 21)) self.radioButton_4.setObjectName("radioButton_4") self.tabWidget.addTab(self.tab_2, "") self.tab_3 = QtWidgets.QWidget() self.tab_3.setObjectName("tab_3") self.lineEdit = QtWidgets.QLineEdit(self.tab_3) self.lineEdit.setGeometry(QtCore.QRect(160, 10, 291, 20)) self.lineEdit.setObjectName("lineEdit") self.lineEdit_2 = QtWidgets.QLineEdit(self.tab_3) self.lineEdit_2.setGeometry(QtCore.QRect(160, 50, 291, 20)) self.lineEdit_2.setObjectName("lineEdit_2") self.lineEdit_3 = QtWidgets.QLineEdit(self.tab_3) self.lineEdit_3.setGeometry(QtCore.QRect(160, 90, 291, 20)) self.lineEdit_3.setObjectName("lineEdit_3") self.lineEdit_4 = QtWidgets.QLineEdit(self.tab_3) self.lineEdit_4.setGeometry(QtCore.QRect(160, 130, 291, 20)) self.lineEdit_4.setObjectName("lineEdit_4") self.lineEdit_5 = QtWidgets.QLineEdit(self.tab_3) self.lineEdit_5.setGeometry(QtCore.QRect(160, 170, 291, 20)) self.lineEdit_5.setObjectName("lineEdit_5") self.lineEdit_6 = QtWidgets.QLineEdit(self.tab_3) self.lineEdit_6.setGeometry(QtCore.QRect(160, 210, 291, 20)) self.lineEdit_6.setObjectName("lineEdit_6") self.label = QtWidgets.QLabel(self.tab_3) self.label.setGeometry(QtCore.QRect(10, 10, 91, 16)) self.label.setObjectName("label") self.label_2 = QtWidgets.QLabel(self.tab_3) self.label_2.setGeometry(QtCore.QRect(10, 50, 71, 16)) self.label_2.setObjectName("label_2") self.label_3 = QtWidgets.QLabel(self.tab_3) self.label_3.setGeometry(QtCore.QRect(10, 90, 47, 13)) self.label_3.setObjectName("label_3") self.label_4 = QtWidgets.QLabel(self.tab_3) self.label_4.setGeometry(QtCore.QRect(10, 130, 71, 21)) self.label_4.setObjectName("label_4") self.label_5 = QtWidgets.QLabel(self.tab_3) self.label_5.setGeometry(QtCore.QRect(10, 170, 71, 16)) self.label_5.setObjectName("label_5") self.label_6 = QtWidgets.QLabel(self.tab_3) self.label_6.setGeometry(QtCore.QRect(10, 210, 121, 16)) self.label_6.setObjectName("label_6") self.tabWidget.addTab(self.tab_3, "") self.retranslateUi(Dialog) self.tabWidget.setCurrentIndex(2) QtCore.QMetaObject.connectSlotsByName(Dialog) def retranslateUi(self, Dialog): _translate = QtCore.QCoreApplication.translate Dialog.setWindowTitle(_translate("Dialog", "Dialog")) self.checkBox.setText(_translate("Dialog", "Cell Phone $150")) self.checkBox_2.setText(_translate("Dialog", "Laptop $500")) self.checkBox_3.setText(_translate("Dialog", "Camera $250")) self.checkBox_4.setText(_translate("Dialog", "Shoes $200")) self.pushButton.setText(_translate("Dialog", "Add to Cart")) self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("Dialog", "Products Listing")) self.radioButton.setText(_translate("Dialog", "Debit Card")) self.radioButton_2.setText(_translate("Dialog", "Credit Card")) self.radioButton_3.setText(_translate("Dialog", "Net Banking")) self.radioButton_4.setText(_translate("Dialog", "Cash On Delivery")) self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), _translate("Dialog", "Payment Method")) self.label.setText(_translate("Dialog", "Address 1")) self.label_2.setText(_translate("Dialog", "Address 2")) self.label_3.setText(_translate("Dialog", "State")) self.label_4.setText(_translate("Dialog", "Country")) self.label_5.setText(_translate("Dialog", "Zip Code")) self.label_6.setText(_translate("Dialog", "Contact Number")) self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_3), _translate("Dialog", "Delivery Address")) if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) Dialog = QtWidgets.QDialog() ui = Ui_Dialog() ui.setupUi(Dialog) Dialog.show() sys.exit(app.exec_()) ================================================ FILE: Chapter03/reservehotel.py ================================================ # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'reservehotel.ui' # # Created by: PyQt5 UI code generator 5.6 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(553, 556) self.label = QtWidgets.QLabel(Dialog) self.label.setGeometry(QtCore.QRect(140, 10, 241, 20)) font = QtGui.QFont() font.setPointSize(17) self.label.setFont(font) self.label.setObjectName("label") self.label_2 = QtWidgets.QLabel(Dialog) self.label_2.setGeometry(QtCore.QRect(10, 60, 161, 20)) font = QtGui.QFont() font.setPointSize(12) self.label_2.setFont(font) self.label_2.setObjectName("label_2") self.label_3 = QtWidgets.QLabel(Dialog) self.label_3.setGeometry(QtCore.QRect(10, 250, 161, 31)) font = QtGui.QFont() font.setPointSize(12) self.label_3.setFont(font) self.label_3.setObjectName("label_3") self.calendarWidget = QtWidgets.QCalendarWidget(Dialog) self.calendarWidget.setGeometry(QtCore.QRect(210, 60, 312, 183)) font = QtGui.QFont() font.setPointSize(12) self.calendarWidget.setFont(font) self.calendarWidget.setObjectName("calendarWidget") self.spinBox = QtWidgets.QSpinBox(Dialog) self.spinBox.setGeometry(QtCore.QRect(210, 260, 42, 22)) font = QtGui.QFont() font.setPointSize(12) self.spinBox.setFont(font) self.spinBox.setObjectName("spinBox") self.label_4 = QtWidgets.QLabel(Dialog) self.label_4.setGeometry(QtCore.QRect(20, 300, 111, 20)) font = QtGui.QFont() font.setPointSize(12) self.label_4.setFont(font) self.label_4.setObjectName("label_4") self.comboBox = QtWidgets.QComboBox(Dialog) self.comboBox.setGeometry(QtCore.QRect(210, 300, 211, 22)) font = QtGui.QFont() font.setPointSize(12) self.comboBox.setFont(font) self.comboBox.setObjectName("comboBox") self.pushButton = QtWidgets.QPushButton(Dialog) self.pushButton.setGeometry(QtCore.QRect(170, 350, 241, 31)) font = QtGui.QFont() font.setPointSize(12) self.pushButton.setFont(font) self.pushButton.setObjectName("pushButton") self.Enteredinfo = QtWidgets.QLabel(Dialog) self.Enteredinfo.setGeometry(QtCore.QRect(20, 400, 501, 51)) font = QtGui.QFont() font.setPointSize(12) self.Enteredinfo.setFont(font) self.Enteredinfo.setText("") self.Enteredinfo.setObjectName("Enteredinfo") self.RoomRentinfo = QtWidgets.QLabel(Dialog) self.RoomRentinfo.setGeometry(QtCore.QRect(10, 480, 501, 51)) font = QtGui.QFont() font.setPointSize(12) self.RoomRentinfo.setFont(font) self.RoomRentinfo.setText("") self.RoomRentinfo.setObjectName("RoomRentinfo") 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", "Hotel Room Reservation")) self.label_2.setText(_translate("Dialog", "Date of Reservation")) self.label_3.setText(_translate("Dialog", "Number of days")) self.label_4.setText(_translate("Dialog", "Room type")) self.pushButton.setText(_translate("Dialog", "Caclulate Room Rent")) ================================================ FILE: Chapter03/reservehotel.ui ================================================ Dialog 0 0 553 556 Dialog 140 10 241 20 17 Hotel Room Reservation 10 60 161 20 12 Date of Reservation 10 250 161 31 12 Number of days 210 60 312 183 12 210 260 42 22 12 20 300 111 20 12 Room type 210 300 211 22 12 170 350 241 31 12 Caclulate Room Rent 20 400 501 51 12 10 480 501 51 12 ================================================ FILE: Chapter04/LineEditClass.py ================================================ # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'demoLineEdit.ui' # # Created by: PyQt5 UI code generator 5.6 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(379, 195) self.label = QtWidgets.QLabel(Dialog) self.label.setGeometry(QtCore.QRect(6, 40, 121, 20)) font = QtGui.QFont() font.setPointSize(11) self.label.setFont(font) self.label.setObjectName("label") self.labelResponse = QtWidgets.QLabel(Dialog) self.labelResponse.setGeometry(QtCore.QRect(40, 90, 271, 20)) font = QtGui.QFont() font.setPointSize(11) self.labelResponse.setFont(font) self.labelResponse.setObjectName("labelResponse") self.lineEditName = QtWidgets.QLineEdit(Dialog) self.lineEditName.setGeometry(QtCore.QRect(140, 40, 201, 20)) font = QtGui.QFont() font.setPointSize(11) self.lineEditName.setFont(font) self.lineEditName.setObjectName("lineEditName") self.ButtonClickMe = QtWidgets.QPushButton(Dialog) self.ButtonClickMe.setGeometry(QtCore.QRect(160, 130, 101, 23)) font = QtGui.QFont() font.setPointSize(11) self.ButtonClickMe.setFont(font) self.ButtonClickMe.setObjectName("ButtonClickMe") 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", "Enter your name")) self.labelResponse.setText(_translate("Dialog", "TextLabel")) self.ButtonClickMe.setText(_translate("Dialog", "Click")) ================================================ FILE: Chapter04/LineEditClass.ui ================================================ Dialog 0 0 379 195 Dialog 6 40 121 20 11 Enter your name 40 90 271 20 11 TextLabel 140 40 201 20 11 160 130 101 23 11 Click ================================================ FILE: Chapter04/callLineEditClass.pyw ================================================ import sys from PyQt5.QtWidgets import QDialog, QApplication from LineEditClass import * class Student: name = "" def __init__(self, name): self.name = name def printName(self): return self.name class MyForm(QDialog): def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.ui.ButtonClickMe.clicked.connect(self.dispmessage) self.show() def dispmessage(self): studentObj=Student(self.ui.lineEditName.text()) self.ui.labelResponse.setText("Hello "+studentObj.printName()) if __name__=="__main__": app = QApplication(sys.argv) w = MyForm() w.show() sys.exit(app.exec_()) ================================================ FILE: Chapter04/callMultilevelInheritance.pyw ================================================ import sys from PyQt5.QtWidgets import QDialog, QApplication from demoMultilevelInheritance import * class Student: name = "" code = "" def __init__(self, code, name): self.code = code self.name = name def getCode(self): return self.code def getName(self): return self.name class Marks(Student): historyMarks = 0 geographyMarks = 0 def __init__(self, code, name, historyMarks, geographyMarks): Student.__init__(self,code,name) self.historyMarks = historyMarks self.geographyMarks = geographyMarks def getHistoryMarks(self): return self.historyMarks def getGeographyMarks(self): return self.geographyMarks class Result(Marks): totalMarks = 0 percentage = 0 def __init__(self, code, name, historyMarks, geographyMarks): Marks.__init__(self, code, name, historyMarks, geographyMarks) self.totalMarks = historyMarks + geographyMarks self.percentage = (historyMarks + geographyMarks) / 200 * 100 def getTotalMarks(self): return self.totalMarks def getPercentage(self): return self.percentage class MyForm(QDialog): def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.ui.ButtonClickMe.clicked.connect(self.dispmessage) self.show() def dispmessage(self): resultObj=Result(self.ui.lineEditCode.text(), self.ui.lineEditName.text(), int(self.ui.lineEditHistoryMarks.text()), int(self.ui.lineEditGeographyMarks.text())) self.ui.lineEditTotal.setText(str(resultObj.getTotalMarks())) self.ui.lineEditPercentage.setText(str(resultObj.getPercentage())) if __name__=="__main__": app = QApplication(sys.argv) w = MyForm() w.show() sys.exit(app.exec_()) ================================================ FILE: Chapter04/callMultipleInheritance.pyw ================================================ import sys from PyQt5.QtWidgets import QDialog, QApplication from demoMultipleInheritance import * class Student: name = "" code = "" def __init__(self, code, name): self.code = code self.name = name def getCode(self): return self.code def getName(self): return self.name class Marks: historyMarks = 0 geographyMarks = 0 def __init__(self, historyMarks, geographyMarks): self.historyMarks = historyMarks self.geographyMarks = geographyMarks def getHistoryMarks(self): return self.historyMarks def getGeographyMarks(self): return self.geographyMarks class Result(Student, Marks): totalMarks = 0 percentage = 0 def __init__(self, code, name, historyMarks, geographyMarks): Student.__init__(self, code, name) Marks.__init__(self, historyMarks, geographyMarks) self.totalMarks = historyMarks + geographyMarks self.percentage = (historyMarks + geographyMarks) / 200 * 100 def getTotalMarks(self): return self.totalMarks def getPercentage(self): return self.percentage class MyForm(QDialog): def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.ui.ButtonClickMe.clicked.connect(self.dispmessage) self.show() def dispmessage(self): resultObj=Result(self.ui.lineEditCode.text(), self.ui.lineEditName.text(), int(self.ui.lineEditHistoryMarks.text()), int(self.ui.lineEditGeographyMarks.text())) self.ui.lineEditTotal.setText(str(resultObj.getTotalMarks())) self.ui.lineEditPercentage.setText(str(resultObj.getPercentage())) if __name__=="__main__": app = QApplication(sys.argv) w = MyForm() w.show() sys.exit(app.exec_()) ================================================ FILE: Chapter04/callSimpleInheritance.pyw ================================================ import sys from PyQt5.QtWidgets import QDialog, QApplication from demoSimpleInheritance import * class Student: name = "" code = "" def __init__(self, code, name): self.code = code self.name = name def getCode(self): return self.code def getName(self): return self.name class Marks(Student): historyMarks = 0 geographyMarks = 0 def __init__(self, code, name, historyMarks, geographyMarks): Student.__init__(self,code,name) self.historyMarks = historyMarks self.geographyMarks = geographyMarks def getHistoryMarks(self): return self.historyMarks def getGeographyMarks(self): return self.geographyMarks class MyForm(QDialog): def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.ui.ButtonClickMe.clicked.connect(self.dispmessage) self.show() def dispmessage(self): marksObj=Marks(self.ui.lineEditCode.text(), self.ui.lineEditName.text(), self.ui.lineEditHistoryMarks.text(), self.ui.lineEditGeographyMarks.text()) self.ui.labelResponse.setText("Code: "+marksObj.getCode()+", Name:"+marksObj.getName()+"\nHistory Marks:"+marksObj.getHistoryMarks()+", Geography Marks:"+marksObj.getGeographyMarks()) if __name__=="__main__": app = QApplication(sys.argv) w = MyForm() w.show() sys.exit(app.exec_()) ================================================ FILE: Chapter04/callStudentClass.pyw ================================================ import sys from PyQt5.QtWidgets import QDialog, QApplication from demoStudentClass import * class Student: name = "" code = "" def __init__(self, code, name): self.code = code self.name = name def getCode(self): return self.code def getName(self): return self.name class MyForm(QDialog): def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.ui.ButtonClickMe.clicked.connect(self.dispmessage) self.show() def dispmessage(self): studentObj=Student(self.ui.lineEditCode.text(), self.ui.lineEditName.text()) self.ui.labelResponse.setText("Code: "+studentObj.getCode()+", Name:"+studentObj.getName()) if __name__=="__main__": app = QApplication(sys.argv) w = MyForm() w.show() sys.exit(app.exec_()) ================================================ FILE: Chapter04/demoMultilevelInheritance.py ================================================ # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'demoMultilevelInheritance.ui' # # Created by: PyQt5 UI code generator 5.6 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(382, 322) self.label = QtWidgets.QLabel(Dialog) self.label.setGeometry(QtCore.QRect(20, 60, 121, 20)) font = QtGui.QFont() font.setPointSize(11) self.label.setFont(font) self.label.setObjectName("label") self.lineEditName = QtWidgets.QLineEdit(Dialog) self.lineEditName.setGeometry(QtCore.QRect(140, 60, 201, 20)) font = QtGui.QFont() font.setPointSize(11) self.lineEditName.setFont(font) self.lineEditName.setObjectName("lineEditName") self.ButtonClickMe = QtWidgets.QPushButton(Dialog) self.ButtonClickMe.setGeometry(QtCore.QRect(150, 280, 101, 23)) font = QtGui.QFont() font.setPointSize(11) self.ButtonClickMe.setFont(font) self.ButtonClickMe.setObjectName("ButtonClickMe") self.lineEditCode = QtWidgets.QLineEdit(Dialog) self.lineEditCode.setGeometry(QtCore.QRect(140, 20, 201, 20)) font = QtGui.QFont() font.setPointSize(11) self.lineEditCode.setFont(font) self.lineEditCode.setObjectName("lineEditCode") self.label_2 = QtWidgets.QLabel(Dialog) self.label_2.setGeometry(QtCore.QRect(20, 20, 121, 20)) font = QtGui.QFont() font.setPointSize(11) self.label_2.setFont(font) self.label_2.setObjectName("label_2") self.lineEditHistoryMarks = QtWidgets.QLineEdit(Dialog) self.lineEditHistoryMarks.setGeometry(QtCore.QRect(140, 100, 201, 20)) font = QtGui.QFont() font.setPointSize(11) self.lineEditHistoryMarks.setFont(font) self.lineEditHistoryMarks.setObjectName("lineEditHistoryMarks") self.label_3 = QtWidgets.QLabel(Dialog) self.label_3.setGeometry(QtCore.QRect(20, 100, 121, 20)) font = QtGui.QFont() font.setPointSize(11) self.label_3.setFont(font) self.label_3.setObjectName("label_3") self.label_4 = QtWidgets.QLabel(Dialog) self.label_4.setGeometry(QtCore.QRect(20, 140, 121, 20)) font = QtGui.QFont() font.setPointSize(11) self.label_4.setFont(font) self.label_4.setObjectName("label_4") self.lineEditGeographyMarks = QtWidgets.QLineEdit(Dialog) self.lineEditGeographyMarks.setGeometry(QtCore.QRect(140, 140, 201, 20)) font = QtGui.QFont() font.setPointSize(11) self.lineEditGeographyMarks.setFont(font) self.lineEditGeographyMarks.setObjectName("lineEditGeographyMarks") self.lineEditPercentage = QtWidgets.QLineEdit(Dialog) self.lineEditPercentage.setEnabled(False) self.lineEditPercentage.setGeometry(QtCore.QRect(140, 220, 201, 20)) font = QtGui.QFont() font.setPointSize(11) self.lineEditPercentage.setFont(font) self.lineEditPercentage.setObjectName("lineEditPercentage") self.label_5 = QtWidgets.QLabel(Dialog) self.label_5.setGeometry(QtCore.QRect(20, 220, 121, 20)) font = QtGui.QFont() font.setPointSize(11) self.label_5.setFont(font) self.label_5.setObjectName("label_5") self.lineEditTotal = QtWidgets.QLineEdit(Dialog) self.lineEditTotal.setEnabled(False) self.lineEditTotal.setGeometry(QtCore.QRect(140, 180, 201, 20)) font = QtGui.QFont() font.setPointSize(11) self.lineEditTotal.setFont(font) self.lineEditTotal.setObjectName("lineEditTotal") self.label_6 = QtWidgets.QLabel(Dialog) self.label_6.setGeometry(QtCore.QRect(20, 180, 121, 20)) font = QtGui.QFont() font.setPointSize(11) self.label_6.setFont(font) self.label_6.setObjectName("label_6") 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", "Student Name")) self.ButtonClickMe.setText(_translate("Dialog", "Click")) self.label_2.setText(_translate("Dialog", "Student Code")) self.label_3.setText(_translate("Dialog", "History Marks")) self.label_4.setText(_translate("Dialog", "Geography Marks")) self.label_5.setText(_translate("Dialog", "Percentage")) self.label_6.setText(_translate("Dialog", "Total")) if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) Dialog = QtWidgets.QDialog() ui = Ui_Dialog() ui.setupUi(Dialog) Dialog.show() sys.exit(app.exec_()) ================================================ FILE: Chapter04/demoMultilevelInheritance.ui ================================================ Dialog 0 0 382 322 Dialog 20 60 121 20 11 Student Name 140 60 201 20 11 150 280 101 23 11 Click 140 20 201 20 11 20 20 121 20 11 Student Code 140 100 201 20 11 20 100 121 20 11 History Marks 20 140 121 20 11 Geography Marks 140 140 201 20 11 false 140 220 201 20 11 20 220 121 20 11 Percentage false 140 180 201 20 11 20 180 121 20 11 Total ================================================ FILE: Chapter04/demoMultipleInheritance.py ================================================ # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'demoMultipleInheritance.ui' # # Created by: PyQt5 UI code generator 5.6 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(382, 322) self.label = QtWidgets.QLabel(Dialog) self.label.setGeometry(QtCore.QRect(20, 60, 121, 20)) font = QtGui.QFont() font.setPointSize(11) self.label.setFont(font) self.label.setObjectName("label") self.lineEditName = QtWidgets.QLineEdit(Dialog) self.lineEditName.setGeometry(QtCore.QRect(140, 60, 201, 20)) font = QtGui.QFont() font.setPointSize(11) self.lineEditName.setFont(font) self.lineEditName.setObjectName("lineEditName") self.ButtonClickMe = QtWidgets.QPushButton(Dialog) self.ButtonClickMe.setGeometry(QtCore.QRect(150, 280, 101, 23)) font = QtGui.QFont() font.setPointSize(11) self.ButtonClickMe.setFont(font) self.ButtonClickMe.setObjectName("ButtonClickMe") self.lineEditCode = QtWidgets.QLineEdit(Dialog) self.lineEditCode.setGeometry(QtCore.QRect(140, 20, 201, 20)) font = QtGui.QFont() font.setPointSize(11) self.lineEditCode.setFont(font) self.lineEditCode.setObjectName("lineEditCode") self.label_2 = QtWidgets.QLabel(Dialog) self.label_2.setGeometry(QtCore.QRect(20, 20, 121, 20)) font = QtGui.QFont() font.setPointSize(11) self.label_2.setFont(font) self.label_2.setObjectName("label_2") self.lineEditHistoryMarks = QtWidgets.QLineEdit(Dialog) self.lineEditHistoryMarks.setGeometry(QtCore.QRect(140, 100, 201, 20)) font = QtGui.QFont() font.setPointSize(11) self.lineEditHistoryMarks.setFont(font) self.lineEditHistoryMarks.setObjectName("lineEditHistoryMarks") self.label_3 = QtWidgets.QLabel(Dialog) self.label_3.setGeometry(QtCore.QRect(20, 100, 121, 20)) font = QtGui.QFont() font.setPointSize(11) self.label_3.setFont(font) self.label_3.setObjectName("label_3") self.label_4 = QtWidgets.QLabel(Dialog) self.label_4.setGeometry(QtCore.QRect(20, 140, 121, 20)) font = QtGui.QFont() font.setPointSize(11) self.label_4.setFont(font) self.label_4.setObjectName("label_4") self.lineEditGeographyMarks = QtWidgets.QLineEdit(Dialog) self.lineEditGeographyMarks.setGeometry(QtCore.QRect(140, 140, 201, 20)) font = QtGui.QFont() font.setPointSize(11) self.lineEditGeographyMarks.setFont(font) self.lineEditGeographyMarks.setObjectName("lineEditGeographyMarks") self.lineEditPercentage = QtWidgets.QLineEdit(Dialog) self.lineEditPercentage.setEnabled(False) self.lineEditPercentage.setGeometry(QtCore.QRect(140, 220, 201, 20)) font = QtGui.QFont() font.setPointSize(11) self.lineEditPercentage.setFont(font) self.lineEditPercentage.setObjectName("lineEditPercentage") self.label_5 = QtWidgets.QLabel(Dialog) self.label_5.setGeometry(QtCore.QRect(20, 220, 121, 20)) font = QtGui.QFont() font.setPointSize(11) self.label_5.setFont(font) self.label_5.setObjectName("label_5") self.lineEditTotal = QtWidgets.QLineEdit(Dialog) self.lineEditTotal.setEnabled(False) self.lineEditTotal.setGeometry(QtCore.QRect(140, 180, 201, 20)) font = QtGui.QFont() font.setPointSize(11) self.lineEditTotal.setFont(font) self.lineEditTotal.setObjectName("lineEditTotal") self.label_6 = QtWidgets.QLabel(Dialog) self.label_6.setGeometry(QtCore.QRect(20, 180, 121, 20)) font = QtGui.QFont() font.setPointSize(11) self.label_6.setFont(font) self.label_6.setObjectName("label_6") 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", "Student Name")) self.ButtonClickMe.setText(_translate("Dialog", "Click")) self.label_2.setText(_translate("Dialog", "Student Code")) self.label_3.setText(_translate("Dialog", "History Marks")) self.label_4.setText(_translate("Dialog", "Geography Marks")) self.label_5.setText(_translate("Dialog", "Percentage")) self.label_6.setText(_translate("Dialog", "Total")) if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) Dialog = QtWidgets.QDialog() ui = Ui_Dialog() ui.setupUi(Dialog) Dialog.show() sys.exit(app.exec_()) ================================================ FILE: Chapter04/demoMultipleInheritance.ui ================================================ Dialog 0 0 382 322 Dialog 20 60 121 20 11 Student Name 140 60 201 20 11 150 280 101 23 11 Click 140 20 201 20 11 20 20 121 20 11 Student Code 140 100 201 20 11 20 100 121 20 11 History Marks 20 140 121 20 11 Geography Marks 140 140 201 20 11 false 140 220 201 20 11 20 220 121 20 11 Percentage false 140 180 201 20 11 20 180 121 20 11 Total ================================================ FILE: Chapter04/demoSimpleInheritance.py ================================================ # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'demoSimpleInheritance.ui' # # Created by: PyQt5 UI code generator 5.6 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(402, 291) self.label = QtWidgets.QLabel(Dialog) self.label.setGeometry(QtCore.QRect(20, 60, 121, 20)) font = QtGui.QFont() font.setPointSize(11) self.label.setFont(font) self.label.setObjectName("label") self.labelResponse = QtWidgets.QLabel(Dialog) self.labelResponse.setGeometry(QtCore.QRect(10, 179, 361, 41)) font = QtGui.QFont() font.setPointSize(11) self.labelResponse.setFont(font) self.labelResponse.setText("") self.labelResponse.setObjectName("labelResponse") self.lineEditName = QtWidgets.QLineEdit(Dialog) self.lineEditName.setGeometry(QtCore.QRect(140, 60, 201, 20)) font = QtGui.QFont() font.setPointSize(11) self.lineEditName.setFont(font) self.lineEditName.setObjectName("lineEditName") self.ButtonClickMe = QtWidgets.QPushButton(Dialog) self.ButtonClickMe.setGeometry(QtCore.QRect(140, 250, 101, 23)) font = QtGui.QFont() font.setPointSize(11) self.ButtonClickMe.setFont(font) self.ButtonClickMe.setObjectName("ButtonClickMe") self.lineEditCode = QtWidgets.QLineEdit(Dialog) self.lineEditCode.setGeometry(QtCore.QRect(140, 20, 201, 20)) font = QtGui.QFont() font.setPointSize(11) self.lineEditCode.setFont(font) self.lineEditCode.setObjectName("lineEditCode") self.label_2 = QtWidgets.QLabel(Dialog) self.label_2.setGeometry(QtCore.QRect(20, 20, 121, 20)) font = QtGui.QFont() font.setPointSize(11) self.label_2.setFont(font) self.label_2.setObjectName("label_2") self.lineEditHistoryMarks = QtWidgets.QLineEdit(Dialog) self.lineEditHistoryMarks.setGeometry(QtCore.QRect(140, 100, 201, 20)) font = QtGui.QFont() font.setPointSize(11) self.lineEditHistoryMarks.setFont(font) self.lineEditHistoryMarks.setObjectName("lineEditHistoryMarks") self.label_3 = QtWidgets.QLabel(Dialog) self.label_3.setGeometry(QtCore.QRect(20, 100, 121, 20)) font = QtGui.QFont() font.setPointSize(11) self.label_3.setFont(font) self.label_3.setObjectName("label_3") self.label_4 = QtWidgets.QLabel(Dialog) self.label_4.setGeometry(QtCore.QRect(20, 140, 121, 20)) font = QtGui.QFont() font.setPointSize(11) self.label_4.setFont(font) self.label_4.setObjectName("label_4") self.lineEditGeographyMarks = QtWidgets.QLineEdit(Dialog) self.lineEditGeographyMarks.setGeometry(QtCore.QRect(140, 140, 201, 20)) font = QtGui.QFont() font.setPointSize(11) self.lineEditGeographyMarks.setFont(font) self.lineEditGeographyMarks.setObjectName("lineEditGeographyMarks") 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", "Student Name")) self.ButtonClickMe.setText(_translate("Dialog", "Click")) self.label_2.setText(_translate("Dialog", "Student Code")) self.label_3.setText(_translate("Dialog", "History Marks")) self.label_4.setText(_translate("Dialog", "Geography Marks")) if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) Dialog = QtWidgets.QDialog() ui = Ui_Dialog() ui.setupUi(Dialog) Dialog.show() sys.exit(app.exec_()) ================================================ FILE: Chapter04/demoSimpleInheritance.ui ================================================ Dialog 0 0 402 291 Dialog 20 60 121 20 11 Student Name 10 179 361 41 11 140 60 201 20 11 140 250 101 23 11 Click 140 20 201 20 11 20 20 121 20 11 Student Code 140 100 201 20 11 20 100 121 20 11 History Marks 20 140 121 20 11 Geography Marks 140 140 201 20 11 ================================================ FILE: Chapter04/demoStudentClass.py ================================================ # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'demoStudentClass.ui' # # Created by: PyQt5 UI code generator 5.6 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(412, 208) self.label = QtWidgets.QLabel(Dialog) self.label.setGeometry(QtCore.QRect(20, 60, 121, 20)) font = QtGui.QFont() font.setPointSize(11) self.label.setFont(font) self.label.setObjectName("label") self.labelResponse = QtWidgets.QLabel(Dialog) self.labelResponse.setGeometry(QtCore.QRect(30, 120, 361, 20)) font = QtGui.QFont() font.setPointSize(11) self.labelResponse.setFont(font) self.labelResponse.setText("") self.labelResponse.setObjectName("labelResponse") self.lineEditName = QtWidgets.QLineEdit(Dialog) self.lineEditName.setGeometry(QtCore.QRect(140, 60, 201, 20)) font = QtGui.QFont() font.setPointSize(11) self.lineEditName.setFont(font) self.lineEditName.setObjectName("lineEditName") self.ButtonClickMe = QtWidgets.QPushButton(Dialog) self.ButtonClickMe.setGeometry(QtCore.QRect(140, 170, 101, 23)) font = QtGui.QFont() font.setPointSize(11) self.ButtonClickMe.setFont(font) self.ButtonClickMe.setObjectName("ButtonClickMe") self.lineEditCode = QtWidgets.QLineEdit(Dialog) self.lineEditCode.setGeometry(QtCore.QRect(140, 20, 201, 20)) font = QtGui.QFont() font.setPointSize(11) self.lineEditCode.setFont(font) self.lineEditCode.setObjectName("lineEditCode") self.label_2 = QtWidgets.QLabel(Dialog) self.label_2.setGeometry(QtCore.QRect(20, 20, 121, 20)) font = QtGui.QFont() font.setPointSize(11) self.label_2.setFont(font) self.label_2.setObjectName("label_2") 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", "Student Name")) self.ButtonClickMe.setText(_translate("Dialog", "Click")) self.label_2.setText(_translate("Dialog", "Student Code")) if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) Dialog = QtWidgets.QDialog() ui = Ui_Dialog() ui.setupUi(Dialog) Dialog.show() sys.exit(app.exec_()) ================================================ FILE: Chapter04/demoStudentClass.ui ================================================ Dialog 0 0 412 208 Dialog 20 60 121 20 11 Student Name 30 120 361 20 11 140 60 201 20 11 140 170 101 23 11 Click 140 20 201 20 11 20 20 121 20 11 Student Code ================================================ FILE: Chapter05/callColorDialog.pyw ================================================ import sys from PyQt5.QtWidgets import QDialog, QApplication, QColorDialog from PyQt5.QtGui import QColor from demoColorDialog import * class MyForm(QDialog): def __init__(self): super().__init__() col = QColor(0, 0, 0) self.ui = Ui_Dialog() self.ui.setupUi(self) self.ui.frameColor.setStyleSheet("QWidget { background-color: %s }" % col.name()) self.ui.pushButtonColor.clicked.connect(self.dispcolor) self.show() def dispcolor(self): col = QColorDialog.getColor() if col.isValid(): self.ui.frameColor.setStyleSheet("QWidget { background-color: %s }" % col.name()) self.ui.labelColor.setText("You have selected the color with code: " + str(col.name())) if __name__=="__main__": app = QApplication(sys.argv) w = MyForm() w.show() sys.exit(app.exec_()) ================================================ FILE: Chapter05/callFileDialog.pyw ================================================ import sys from PyQt5.QtWidgets import QMainWindow, QApplication, QAction, QFileDialog from demoFileDialog import * class MyForm(QMainWindow): def __init__(self): super().__init__() self.ui = Ui_MainWindow() self.ui.setupUi(self) self.ui.actionOpen.triggered.connect(self.openFileDialog) self.ui.actionSave.triggered.connect(self.saveFileDialog) self.show() def openFileDialog(self): fname = QFileDialog.getOpenFileName(self, 'Open file', '/home') if fname[0]: f = open(fname[0], 'r') with f: data = f.read() self.ui.textEdit.setText(data) def saveFileDialog(self): options = QFileDialog.Options() options |= QFileDialog.DontUseNativeDialog fileName, _ = QFileDialog.getSaveFileName(self,"QFileDialog.getSaveFileName()","","All Files (*);;Text Files (*.txt)", options=options) f = open(fileName,'w') text = self.ui.textEdit.toPlainText() f.write(text) f.close() if __name__=="__main__": app = QApplication(sys.argv) w = MyForm() w.show() sys.exit(app.exec_()) ================================================ FILE: Chapter05/callFontDialog.pyw ================================================ import sys from PyQt5.QtWidgets import QDialog, QApplication, QFontDialog from demoFontDialog import * class MyForm(QDialog): def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.ui.pushButtonFont.clicked.connect(self.changefont) self.show() def changefont(self): font, ok = QFontDialog.getFont() if ok: self.ui.textEdit.setFont(font) if __name__=="__main__": app = QApplication(sys.argv) w = MyForm() w.show() sys.exit(app.exec_()) ================================================ FILE: Chapter05/callInputDialog.pyw ================================================ import sys from PyQt5.QtWidgets import QDialog, QApplication, QInputDialog from demoInputDialog import * class MyForm(QDialog): def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.ui.pushButtonCountry.clicked.connect(self.dispmessage) self.show() def dispmessage(self): countries = ("Albania", "Algeria", "Andorra", "Angola", "Antigua and Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan") countryName, ok = QInputDialog.getItem(self, "Input Dialog", "List of countries", countries, 0, False) if ok and countryName: self.ui.lineEditCountry.setText(countryName) if __name__=="__main__": app = QApplication(sys.argv) w = MyForm() w.show() sys.exit(app.exec_()) ================================================ FILE: Chapter05/demoColorDialog.py ================================================ # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'demoColorDialog.ui' # # Created by: PyQt5 UI code generator 5.6 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(400, 176) self.frameColor = QtWidgets.QFrame(Dialog) self.frameColor.setGeometry(QtCore.QRect(210, 20, 120, 80)) font = QtGui.QFont() font.setPointSize(12) self.frameColor.setFont(font) self.frameColor.setFrameShape(QtWidgets.QFrame.StyledPanel) self.frameColor.setFrameShadow(QtWidgets.QFrame.Raised) self.frameColor.setObjectName("frameColor") self.pushButtonColor = QtWidgets.QPushButton(Dialog) self.pushButtonColor.setGeometry(QtCore.QRect(30, 40, 151, 23)) font = QtGui.QFont() font.setPointSize(12) self.pushButtonColor.setFont(font) self.pushButtonColor.setObjectName("pushButtonColor") self.labelColor = QtWidgets.QLabel(Dialog) self.labelColor.setGeometry(QtCore.QRect(30, 130, 351, 20)) font = QtGui.QFont() font.setPointSize(12) self.labelColor.setFont(font) self.labelColor.setText("") self.labelColor.setObjectName("labelColor") self.retranslateUi(Dialog) QtCore.QMetaObject.connectSlotsByName(Dialog) def retranslateUi(self, Dialog): _translate = QtCore.QCoreApplication.translate Dialog.setWindowTitle(_translate("Dialog", "Dialog")) self.pushButtonColor.setText(_translate("Dialog", "Choose color")) ================================================ FILE: Chapter05/demoColorDialog.ui ================================================ Dialog 0 0 400 176 Dialog 210 20 120 80 12 QFrame::StyledPanel QFrame::Raised 30 40 151 23 12 Choose color 30 130 351 20 12 ================================================ FILE: Chapter05/demoFileDialog.py ================================================ # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'demoFileDialog.ui' # # Created by: PyQt5 UI code generator 5.6 # # 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(516, 374) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.textEdit = QtWidgets.QTextEdit(self.centralwidget) self.textEdit.setGeometry(QtCore.QRect(0, 10, 521, 331)) self.textEdit.setObjectName("textEdit") MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 516, 21)) self.menubar.setObjectName("menubar") self.menuFile = QtWidgets.QMenu(self.menubar) self.menuFile.setObjectName("menuFile") MainWindow.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.actionOpen = QtWidgets.QAction(MainWindow) self.actionOpen.setObjectName("actionOpen") self.actionSave = QtWidgets.QAction(MainWindow) self.actionSave.setObjectName("actionSave") self.menuFile.addAction(self.actionOpen) self.menuFile.addAction(self.actionSave) self.menubar.addAction(self.menuFile.menuAction()) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) self.menuFile.setTitle(_translate("MainWindow", "File")) self.actionOpen.setText(_translate("MainWindow", "Open")) self.actionOpen.setShortcut(_translate("MainWindow", "Ctrl+O")) self.actionSave.setText(_translate("MainWindow", "Save")) self.actionSave.setShortcut(_translate("MainWindow", "Ctrl+S")) ================================================ FILE: Chapter05/demoFileDialog.ui ================================================ MainWindow 0 0 544 386 MainWindow 0 10 521 331 0 0 544 21 File Open Ctrl+O Save Ctrl+S ================================================ FILE: Chapter05/demoFontDialog.py ================================================ # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'demoFontDialog.ui' # # Created by: PyQt5 UI code generator 5.6 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(400, 300) self.textEdit = QtWidgets.QTextEdit(Dialog) self.textEdit.setGeometry(QtCore.QRect(30, 60, 331, 221)) self.textEdit.setObjectName("textEdit") self.pushButtonFont = QtWidgets.QPushButton(Dialog) self.pushButtonFont.setGeometry(QtCore.QRect(120, 10, 111, 31)) font = QtGui.QFont() font.setPointSize(12) self.pushButtonFont.setFont(font) self.pushButtonFont.setObjectName("pushButtonFont") self.retranslateUi(Dialog) QtCore.QMetaObject.connectSlotsByName(Dialog) def retranslateUi(self, Dialog): _translate = QtCore.QCoreApplication.translate Dialog.setWindowTitle(_translate("Dialog", "Dialog")) self.pushButtonFont.setText(_translate("Dialog", "Change Font")) ================================================ FILE: Chapter05/demoFontDialog.ui ================================================ Dialog 0 0 400 300 Dialog 30 60 331 221 120 10 111 31 12 Change Font ================================================ FILE: Chapter05/demoInputDialog.py ================================================ from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(565, 74) self.label = QtWidgets.QLabel(Dialog) self.label.setGeometry(QtCore.QRect(20, 20, 131, 20)) font = QtGui.QFont() font.setPointSize(12) self.label.setFont(font) self.label.setObjectName("label") self.lineEditCountry = QtWidgets.QLineEdit(Dialog) self.lineEditCountry.setGeometry(QtCore.QRect(140, 20, 221, 20)) font = QtGui.QFont() font.setPointSize(12) self.lineEditCountry.setFont(font) self.lineEditCountry.setObjectName("lineEditCountry") self.pushButtonCountry = QtWidgets.QPushButton(Dialog) self.pushButtonCountry.setGeometry(QtCore.QRect(400, 20, 131, 23)) font = QtGui.QFont() font.setPointSize(12) self.pushButtonCountry.setFont(font) self.pushButtonCountry.setObjectName("pushButtonCountry") 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", "Your Country:")) self.pushButtonCountry.setText(_translate("Dialog", "Choose Country")) if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) Dialog = QtWidgets.QDialog() ui = Ui_Dialog() ui.setupUi(Dialog) Dialog.show() sys.exit(app.exec_()) ================================================ FILE: Chapter05/demoInputDialog.ui ================================================ Dialog 0 0 565 74 Dialog 20 20 131 20 12 Your Country: 140 20 221 20 12 400 20 131 23 12 Choose Country ================================================ FILE: Chapter07/callServer.pyw ================================================ import sys, time import socket from PyQt5 import QtGui from PyQt5 import QtCore from PyQt5.QtWidgets import QApplication, QDialog from PyQt5.QtCore import QCoreApplication from threading import Thread from socketserver import ThreadingMixIn from demoServer import * conn=None class Window(QDialog): def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.textEditMessages=self.ui.textEditMessages self.ui.pushButtonSend.clicked.connect(self.dispMessage) self.show() def dispMessage(self): text=self.ui.lineEditMessage.text() global conn conn.send(text.encode("utf-8")) self.ui.textEditMessages.append("Server: "+self.ui.lineEditMessage.text()) self.ui.lineEditMessage.setText("") class ServerThread(Thread): def __init__(self,window): Thread.__init__(self) self.window=window def run(self): TCP_IP = '0.0.0.0' TCP_PORT = 80 BUFFER_SIZE = 1024 tcpServer = socket.socket(socket.AF_INET, socket.SOCK_STREAM) tcpServer.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) tcpServer.bind((TCP_IP, TCP_PORT)) threads = [] tcpServer.listen(4) while True: global conn (conn, (ip,port)) = tcpServer.accept() newthread = ClientThread(ip,port,window) newthread.start() threads.append(newthread) for t in threads: t.join() class ClientThread(Thread): def __init__(self,ip,port,window): Thread.__init__(self) self.window=window self.ip = ip self.port = port def run(self): while True : global conn data = conn.recv(1024) window.textEditMessages.append("Client: "+data.decode("utf-8")) if __name__=="__main__": app = QApplication(sys.argv) window = Window() serverThread=ServerThread(window) serverThread.start() window.exec() sys.exit(app.exec_()) ================================================ FILE: Chapter07/demoBrowser.py ================================================ # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'demoBrowser.ui' # # Created by: PyQt5 UI code generator 5.6 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(563, 339) self.widget = QWebEngineView(Dialog) self.widget.setGeometry(QtCore.QRect(10, 60, 531, 251)) self.widget.setObjectName("widget") self.pushButtonGo = QtWidgets.QPushButton(Dialog) self.pushButtonGo.setGeometry(QtCore.QRect(450, 20, 91, 23)) font = QtGui.QFont() font.setPointSize(12) self.pushButtonGo.setFont(font) self.pushButtonGo.setObjectName("pushButtonGo") self.lineEditURL = QtWidgets.QLineEdit(Dialog) self.lineEditURL.setGeometry(QtCore.QRect(100, 20, 331, 21)) font = QtGui.QFont() font.setPointSize(12) self.lineEditURL.setFont(font) self.lineEditURL.setObjectName("lineEditURL") self.label = QtWidgets.QLabel(Dialog) self.label.setGeometry(QtCore.QRect(10, 20, 71, 16)) font = QtGui.QFont() font.setPointSize(12) self.label.setFont(font) self.label.setObjectName("label") self.retranslateUi(Dialog) QtCore.QMetaObject.connectSlotsByName(Dialog) def retranslateUi(self, Dialog): _translate = QtCore.QCoreApplication.translate Dialog.setWindowTitle(_translate("Dialog", "Dialog")) self.pushButtonGo.setText(_translate("Dialog", "Go")) self.label.setText(_translate("Dialog", "Enter URL")) from PyQt5.QtWebEngineWidgets import QWebEngineView if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) Dialog = QtWidgets.QDialog() ui = Ui_Dialog() ui.setupUi(Dialog) Dialog.show() sys.exit(app.exec_()) ================================================ FILE: Chapter07/demoDockWidget.ui ================================================ MainWindow 0 0 637 440 MainWindow 0 0 637 21 QDockWidget::AllDockWidgetFeatures Qt::AllDockWidgetAreas Dockable Sign In Form 1 130 10 91 21 12 Sign In 10 60 111 20 12 Email Address 120 60 161 20 12 20 110 81 16 12 Password 100 150 75 23 12 Sign In 120 110 151 20 12 ================================================ FILE: Chapter07/demoMenuBar.py ================================================ # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'demoMenuBar.ui' # # Created by: PyQt5 UI code generator 5.6 # # 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(463, 341) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.label = QtWidgets.QLabel(self.centralwidget) self.label.setGeometry(QtCore.QRect(20, 110, 421, 20)) font = QtGui.QFont() font.setPointSize(12) self.label.setFont(font) self.label.setText("") self.label.setObjectName("label") MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 463, 21)) self.menubar.setObjectName("menubar") self.menuDraw = QtWidgets.QMenu(self.menubar) self.menuDraw.setObjectName("menuDraw") self.menuProperties = QtWidgets.QMenu(self.menuDraw) self.menuProperties.setObjectName("menuProperties") self.menuEdit = QtWidgets.QMenu(self.menubar) self.menuEdit.setObjectName("menuEdit") MainWindow.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.actionDraw_Circle = QtWidgets.QAction(MainWindow) self.actionDraw_Circle.setObjectName("actionDraw_Circle") self.actionDraw_Rectangle = QtWidgets.QAction(MainWindow) self.actionDraw_Rectangle.setObjectName("actionDraw_Rectangle") self.actionDraw_Line = QtWidgets.QAction(MainWindow) self.actionDraw_Line.setObjectName("actionDraw_Line") self.actionPage_Setup = QtWidgets.QAction(MainWindow) self.actionPage_Setup.setObjectName("actionPage_Setup") self.actionSet_Password = QtWidgets.QAction(MainWindow) self.actionSet_Password.setCheckable(True) self.actionSet_Password.setObjectName("actionSet_Password") self.actionCut = QtWidgets.QAction(MainWindow) self.actionCut.setObjectName("actionCut") self.actionCopy = QtWidgets.QAction(MainWindow) self.actionCopy.setObjectName("actionCopy") self.actionPaste = QtWidgets.QAction(MainWindow) self.actionPaste.setObjectName("actionPaste") self.menuProperties.addAction(self.actionPage_Setup) self.menuProperties.addAction(self.actionSet_Password) self.menuDraw.addAction(self.actionDraw_Circle) self.menuDraw.addAction(self.actionDraw_Rectangle) self.menuDraw.addAction(self.actionDraw_Line) self.menuDraw.addSeparator() self.menuDraw.addAction(self.menuProperties.menuAction()) self.menuEdit.addAction(self.actionCut) self.menuEdit.addAction(self.actionCopy) self.menuEdit.addAction(self.actionPaste) self.menubar.addAction(self.menuDraw.menuAction()) self.menubar.addAction(self.menuEdit.menuAction()) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) self.menuDraw.setTitle(_translate("MainWindow", "Draw")) self.menuProperties.setTitle(_translate("MainWindow", "Properties")) self.menuEdit.setTitle(_translate("MainWindow", "Edit")) self.actionDraw_Circle.setText(_translate("MainWindow", "Draw Circle")) self.actionDraw_Circle.setToolTip(_translate("MainWindow", "To draw a circle")) self.actionDraw_Circle.setShortcut(_translate("MainWindow", "Shift+C")) self.actionDraw_Rectangle.setText(_translate("MainWindow", "Draw Rectangle")) self.actionDraw_Rectangle.setShortcut(_translate("MainWindow", "Ctrl+R")) self.actionDraw_Line.setText(_translate("MainWindow", "Draw Line")) self.actionDraw_Line.setShortcut(_translate("MainWindow", "Ctrl+L")) self.actionPage_Setup.setText(_translate("MainWindow", "Page Setup")) self.actionPage_Setup.setShortcut(_translate("MainWindow", "Shift+S")) self.actionSet_Password.setText(_translate("MainWindow", "Set Password")) self.actionSet_Password.setShortcut(_translate("MainWindow", "Shift+P")) self.actionCut.setText(_translate("MainWindow", "Cut")) self.actionCut.setShortcut(_translate("MainWindow", "Ctrl+X")) self.actionCopy.setText(_translate("MainWindow", "Copy")) self.actionCopy.setShortcut(_translate("MainWindow", "Ctrl+C")) self.actionPaste.setText(_translate("MainWindow", "Paste")) self.actionPaste.setShortcut(_translate("MainWindow", "Ctrl+V")) 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_()) ================================================ FILE: Chapter07/demoTabWidget.ui ================================================ Dialog 0 0 574 300 Dialog 10 10 481 271 12 2 Products Listing 30 30 191 17 Cell Phone $150 30 70 141 17 Laptop $500 30 110 161 17 Camera $250 30 150 171 17 Shoes $200 40 190 141 23 Add to Cart Payment Method 40 30 131 17 Debit Card 40 80 111 17 Credit Card 40 130 121 21 Net Banking 40 180 181 21 Cash On Delivery Delivery Address 160 10 291 20 160 50 291 20 160 90 291 20 160 130 291 20 160 170 291 20 160 210 291 20 10 10 91 16 Address 1 10 50 71 16 Address 2 10 90 47 13 State 10 130 71 21 Country 10 170 71 16 Zip Code 10 210 121 16 Contact Number ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2018 Packt Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # Qt5 Python GUI Programming Cookbook Qt5 Python GUI Programming Cookbook This is the code repository for [Qt5 Python GUI Programming Cookbook](https://www.packtpub.com/application-development/qt5-python-gui-programming-cookbook?utm_source=github&utm_medium=repository&utm_campaign=9781788831000 ), published by Packt. ** Building responsive and powerful cross-platform applications with PyQt** ## What is this book about? PyQt is one of the best cross-platform interface toolkits currently available; it's stable, mature, and completely native. If you want control over all aspects of UI elements, PyQt is what you need. This book will guide you through every concept necessary to create fully functional GUI applications using PyQt, with only a few lines of code. This book covers the following exciting features: Use basic Qt components, such as a radio button, combo box, and sliders Use QSpinBox and sliders to handle different signals generated on mouse clicks Work with different Qt layouts to meet user interface requirements Create custom widgets and set up customizations in your GUI Perform asynchronous I/O operations and thread handling in the Python GUI Employ network concepts, internet browsing, and Google Maps in UI Use graphics rendering and implement animation in your GUI Make your GUI application compatible with Android and iOS devices If you feel this book is for you, get your [copy](https://www.amazon.com/dp/1-788-83100-4) today! https://www.packtpub.com/ ## Instructions and Navigations All of the code is organized into folders. For example, Chapter02. The code will look like the following: ``` import sys from PyQt5.QtWidgets import QDialog, QApplication from demoCalendar import * class MyForm(QDialog): def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.ui.calendarWidget.selectionChanged.connect (self.dispdate) self.show() def dispdate(self): self.ui.dateEdit.setDate(self.ui.calendarWidget. selectedDate()) if __name__=="__main__": app = QApplication(sys.argv) w = MyForm() w.show() sys.exit(app.exec_()) ``` **Following is what you need for this book:** If you’re an intermediate Python programmer wishing to enhance your coding skills by writing powerful GUIs in Python using PyQT, this is the book for you. With the following software and hardware list you can run all code files present in the book (Chapter 1-13). ### Software and Hardware List | Chapter | Software required | OS required | | -------- | ------------------------------------ | ----------------------------------- | | 1-8,10-12 | Python 3.5.0 | Windows, Mac OS X, and Linux (Any) | | 1-8, 10-12 | PyQt5 version 5.6 | Windows, Mac OS X, and Linux (Any) | | 9 | SQLite 3 | Windows, Mac OS X, and Linux (Any) | | 9 | DB Browser for SQLite | Windows, Mac OS X, and Linux (Any) | | 13 | QPython | Windows, Mac OS X, and Linux (Any) | | 13 | Cython | Windows, Mac OS X, and Linux (Any) | | 13 | Kivy | Windows, Mac OS X, and Linux (Any) | | 13 | Oracle VM VirtualBox | Windows, Mac OS X, and Linux (Any) | | 13 | Kivy Buildozer VM | Windows, Mac OS X, and Linux (Any) | | 13 | XCode and libraries | Windows, Mac OS X, and Linux (Any) | We also provide a PDF file that has color images of the screenshots/diagrams used in this book. [Click here to download it](https://www.packtpub.com/sites/default/files/downloads/Qt5PythonGUIProgrammingCookbook_ColorImages.pdf). ### Related products * Computer Vision with OpenCV 3 and Qt5: Build visually appealing, multithreaded, cross-platform computer vision applications Paperback – January 2, 2018 [[Packt]](https://www.amazon.com/Computer-Vision-OpenCV-multithreaded-cross-platform/dp/178847239X/ref=sr_1_1?ie=UTF8&qid=1532586055&sr=8-1&keywords=Computer+Vision+with+OpenCV+3+and+Qt5&dpID=51Z4u1hLAzL&preST=_SX218_BO1,204,203,200_QL40_&dpSrc=srch&utm_source=github&utm_medium=repository&utm_campaign=) [[Amazon]](https://www.amazon.com/dp/1-788-47239-X) * Qt 5 Projects: Develop cross-platform applications with modern UIs using the powerful Qt framework Paperback – February 23, 2018 [[Packt]](https://www.amazon.com/Qt-Projects-cross-platform-applications-framework/dp/1788293886/ref=sr_1_2_sspa?s=books&ie=UTF8&qid=1532586126&sr=1-2-spons&keywords=Qt+5+Projects&psc=1&utm_source=github&utm_medium=repository&utm_campaign=) [[Amazon]](https://www.amazon.com/dp/) * [[Packt]]() [[Amazon]](https://www.amazon.com/dp/) * [[Packt]]() [[Amazon]](https://www.amazon.com/dp/) ## Get to Know the Author **BM Harwani** is the founder and owner of Microchip Computer Education (MCE), based in Ajmer, India. He graduated with a BE in computer engineering from the University of Pune and also has a C level (masters diploma in computer technology) from DOEACC, Government of India. Having been involved in the teaching field for over 20 years, he has developed the art of explaining even the most complicated topics in a straightforward and easily understandable fashion. He is also a renowned speaker and the author of several books. To learn more, visit his blog, a site that helps programmers. **** 0 **** 0 **** 0 **** 0 ## Other books by the authors []() []() []() []() []() ### Suggestions and Feedback [Click here](https://docs.google.com/forms/d/e/1FAIpQLSdy7dATC6QmEL81FIUuymZ0Wy9vH1jHkvpY57OiMeKGqib_Ow/viewform) if you have any feedback or suggestions. ### Download a free PDF If you have already purchased a print or Kindle version of this book, you can get a DRM-free PDF version at no cost.
Simply click on the link to claim your free PDF.

https://packt.link/free-ebook/9781788831000