diff --git a/TechWithTim/QtDesigner_intro/combo_box/test.py b/TechWithTim/QtDesigner_intro/combo_box/test.py new file mode 100644 index 0000000..92a8326 --- /dev/null +++ b/TechWithTim/QtDesigner_intro/combo_box/test.py @@ -0,0 +1,95 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file 'test.ui' +# +# Created by: PyQt5 UI code generator 5.15.4 +# +# WARNING: Any manual changes made to this file will be lost when pyuic5 is +# run again. Do not edit this file unless you know what you are doing. + + +from PyQt5 import QtCore, QtGui, QtWidgets + + +class Ui_MainWindow(object): + def setupUi(self, MainWindow): + MainWindow.setObjectName("MainWindow") + MainWindow.resize(800, 600) + self.centralwidget = QtWidgets.QWidget(MainWindow) + self.centralwidget.setObjectName("centralwidget") + self.comboX = QtWidgets.QComboBox(self.centralwidget) + self.comboX.setGeometry(QtCore.QRect(60, 80, 221, 111)) + font = QtGui.QFont() + font.setPointSize(20) + self.comboX.setFont(font) + self.comboX.setObjectName("comboX") + self.comboX.addItem("") + self.comboX.addItem("") + self.comboY = QtWidgets.QComboBox(self.centralwidget) + self.comboY.setGeometry(QtCore.QRect(510, 80, 221, 111)) + font = QtGui.QFont() + font.setPointSize(20) + self.comboY.setFont(font) + self.comboY.setObjectName("comboY") + self.comboY.addItem("") + self.comboY.addItem("") + self.submit = QtWidgets.QPushButton(self.centralwidget) + self.submit.setGeometry(QtCore.QRect(250, 370, 271, 101)) + font = QtGui.QFont() + font.setPointSize(20) + self.submit.setFont(font) + self.submit.setObjectName("submit") + self.label = QtWidgets.QLabel(self.centralwidget) + self.label.setGeometry(QtCore.QRect(220, 240, 311, 91)) + font = QtGui.QFont() + font.setPointSize(20) + self.label.setFont(font) + self.label.setObjectName("label") + MainWindow.setCentralWidget(self.centralwidget) + self.menubar = QtWidgets.QMenuBar(MainWindow) + self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26)) + self.menubar.setObjectName("menubar") + MainWindow.setMenuBar(self.menubar) + self.statusbar = QtWidgets.QStatusBar(MainWindow) + self.statusbar.setObjectName("statusbar") + MainWindow.setStatusBar(self.statusbar) + + # Add new item to combo box. + # self.comboX.addItem("Hello") + # Set it as initial value + # index = self.comboX.findText("Hello", QtCore.Qt.MatchFixedString) + # self.comboX.setCurrentIndex(index) + + self.submit.clicked.connect(self.pressed) + + self.retranslateUi(MainWindow) + QtCore.QMetaObject.connectSlotsByName(MainWindow) + + def retranslateUi(self, MainWindow): + _translate = QtCore.QCoreApplication.translate + MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) + self.comboX.setItemText(0, _translate("MainWindow", "0")) + self.comboX.setItemText(1, _translate("MainWindow", "1")) + self.comboY.setItemText(0, _translate("MainWindow", "0")) + self.comboY.setItemText(1, _translate("MainWindow", "1")) + self.submit.setText(_translate("MainWindow", "Submit")) + self.label.setText(_translate("MainWindow", "X xor Y =")) + + def pressed(self): + x = int(self.comboX.currentText()) + y = int(self.comboY.currentText()) + xor = (x and not y) or (not x and y) + if xor == True: + xor = 1 + else : + xor = 0 + self.label.setText("X xor Y = " + str(xor) ) + +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_()) diff --git a/TechWithTim/QtDesigner_intro/combo_box/test.ui b/TechWithTim/QtDesigner_intro/combo_box/test.ui new file mode 100644 index 0000000..d9b95c2 --- /dev/null +++ b/TechWithTim/QtDesigner_intro/combo_box/test.ui @@ -0,0 +1,118 @@ + + + MainWindow + + + + 0 + 0 + 800 + 600 + + + + MainWindow + + + + + + 60 + 80 + 221 + 111 + + + + + 20 + + + + + 0 + + + + + 1 + + + + + + + 510 + 80 + 221 + 111 + + + + + 20 + + + + + 0 + + + + + 1 + + + + + + + 250 + 370 + 271 + 101 + + + + + 20 + + + + Submit + + + + + + 220 + 240 + 311 + 91 + + + + + 20 + + + + X xor Y = + + + + + + + 0 + 0 + 800 + 26 + + + + + + + +