-
Notifications
You must be signed in to change notification settings - Fork 0
/
comboBoxes.py
104 lines (92 loc) · 4.05 KB
/
comboBoxes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'form.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(70, 120, 261, 111))
font = QtGui.QFont()
font.setPointSize(22)
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(400, 120, 281, 111))
font = QtGui.QFont()
font.setPointSize(22)
self.comboY.setFont(font)
self.comboY.setObjectName("comboY")
self.comboY.addItem("")
self.comboY.addItem("")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(250, 380, 261, 101))
font = QtGui.QFont()
font.setPointSize(22)
self.pushButton.setFont(font)
self.pushButton.setObjectName("pushButton")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(250, 310, 261, 31))
font = QtGui.QFont()
font.setPointSize(20)
self.label.setFont(font)
self.label.setAutoFillBackground(False)
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.label.setObjectName("label")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 22))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
# to change the values in the combo box by code
# self.comboX.addItem("Hello!")
# # to change the default selected value (besides the first)
# # if it doesn't exist it will return -1
# index = self.comboX.findText("Hello!", QtCore.Qt.MatchFixedString)
# self.comboX.setCurrentIndex(index)
self.pushButton.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.pushButton.setText(_translate("MainWindow", "Submit"))
self.label.setText(_translate("MainWindow", "X XOR Y = "))
def pressed(self):
# print(self.comboX.currentText())
# print(self.comboY.currentText())
x = int(self.comboX.currentText())
y = int(self.comboY.currentText())
# implemenation of xor value
xor = (x and not y) or (not x and y)
if xor:
xor = 1
else:
xor = 0
# update the label by adding the xor to the end of the current text
# self.label.setText(self.label.text() + " " + str(xor))
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_())