Adding combo box tutorial.
This commit is contained in:
parent
5ca4d0083c
commit
a71c1ddb35
95
TechWithTim/QtDesigner_intro/combo_box/test.py
Normal file
95
TechWithTim/QtDesigner_intro/combo_box/test.py
Normal file
@ -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_())
|
118
TechWithTim/QtDesigner_intro/combo_box/test.ui
Normal file
118
TechWithTim/QtDesigner_intro/combo_box/test.ui
Normal file
@ -0,0 +1,118 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<widget class="QComboBox" name="comboX">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>60</x>
|
||||
<y>80</y>
|
||||
<width>221</width>
|
||||
<height>111</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>20</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>0</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>1</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
<widget class="QComboBox" name="comboY">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>510</x>
|
||||
<y>80</y>
|
||||
<width>221</width>
|
||||
<height>111</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>20</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>0</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>1</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="submit">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>250</x>
|
||||
<y>370</y>
|
||||
<width>271</width>
|
||||
<height>101</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>20</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Submit</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>220</x>
|
||||
<y>240</y>
|
||||
<width>311</width>
|
||||
<height>91</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>20</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>X xor Y =</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>26</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
Loading…
x
Reference in New Issue
Block a user