How to update value of QLCDNumber on PyQT5? - python

I am trying to update my QLCDNumber, but I failed several times. In my code, you can see that I want to take the input numbers from the double spin boxes and show them as a total sum of the previous land use values in my LCD widget. I have created a function with .value() but it doesn't work properly. The code is bit large, but I highlighted the QLCDNumber part.
Screenshot here:
values to take as inputs
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1039, 654)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.tabWidget = QtWidgets.QTabWidget(self.centralwidget)
self.tabWidget.setGeometry(QtCore.QRect(10, 0, 1001, 621))
self.tabWidget.setObjectName("tabWidget")
self.tab = QtWidgets.QWidget()
self.tab.setObjectName("tab")
self.groupBox = QtWidgets.QGroupBox(self.tab)
self.groupBox.setGeometry(QtCore.QRect(10, 40, 241, 521))
font = QtGui.QFont()
font.setPointSize(11)
self.groupBox.setFont(font)
self.groupBox.setTitle("")
self.groupBox.setObjectName("groupBox")
self.layoutWidget_5 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_5.setGeometry(QtCore.QRect(0, 50, 234, 26))
self.layoutWidget_5.setObjectName("layoutWidget_5")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.layoutWidget_5)
self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.grass_label = QtWidgets.QLabel(self.layoutWidget_5)
font = QtGui.QFont()
font.setPointSize(12)
self.grass_label.setFont(font)
self.grass_label.setObjectName("grass_label")
self.horizontalLayout_2.addWidget(self.grass_label)
self.grass_value = QtWidgets.QDoubleSpinBox(self.layoutWidget_5)
self.grass_value.setSingleStep(0.05)
self.grass_value.setObjectName("grass_value")
self.horizontalLayout_2.addWidget(self.grass_value)
self.layoutWidget_6 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_6.setGeometry(QtCore.QRect(0, 80, 234, 26))
self.layoutWidget_6.setObjectName("layoutWidget_6")
self.horizontalLayout_3 = QtWidgets.QHBoxLayout(self.layoutWidget_6)
self.horizontalLayout_3.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.arable_label = QtWidgets.QLabel(self.layoutWidget_6)
font = QtGui.QFont()
font.setPointSize(12)
self.arable_label.setFont(font)
self.arable_label.setObjectName("arable_label")
self.horizontalLayout_3.addWidget(self.arable_label)
self.arab_value = QtWidgets.QDoubleSpinBox(self.layoutWidget_6)
self.arab_value.setSingleStep(0.05)
self.arab_value.setObjectName("arab_value")
self.horizontalLayout_3.addWidget(self.arab_value)
self.layoutWidget_7 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_7.setGeometry(QtCore.QRect(0, 110, 234, 26))
self.layoutWidget_7.setObjectName("layoutWidget_7")
self.horizontalLayout_4 = QtWidgets.QHBoxLayout(self.layoutWidget_7)
self.horizontalLayout_4.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.woodl_label = QtWidgets.QLabel(self.layoutWidget_7)
font = QtGui.QFont()
font.setPointSize(12)
self.woodl_label.setFont(font)
self.woodl_label.setObjectName("woodl_label")
self.horizontalLayout_4.addWidget(self.woodl_label)
self.wood_value = QtWidgets.QDoubleSpinBox(self.layoutWidget_7)
self.wood_value.setSingleStep(0.05)
self.wood_value.setObjectName("wood_value")
self.horizontalLayout_4.addWidget(self.wood_value)
self.layoutWidget_8 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_8.setGeometry(QtCore.QRect(0, 140, 234, 26))
self.layoutWidget_8.setObjectName("layoutWidget_8")
self.horizontalLayout_5 = QtWidgets.QHBoxLayout(self.layoutWidget_8)
self.horizontalLayout_5.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_5.setObjectName("horizontalLayout_5")
self.mount_label = QtWidgets.QLabel(self.layoutWidget_8)
font = QtGui.QFont()
font.setPointSize(12)
self.mount_label.setFont(font)
self.mount_label.setObjectName("mount_label")
self.horizontalLayout_5.addWidget(self.mount_label)
self.mount_value = QtWidgets.QDoubleSpinBox(self.layoutWidget_8)
self.mount_value.setSingleStep(0.05)
self.mount_value.setObjectName("mount_value")
self.horizontalLayout_5.addWidget(self.mount_value)
self.start_butt = QtWidgets.QPushButton(self.groupBox)
self.start_butt.setGeometry(QtCore.QRect(50, 290, 113, 32))
self.start_butt.setObjectName("start_butt")
self.landuse_label = QtWidgets.QLabel(self.groupBox)
self.landuse_label.setGeometry(QtCore.QRect(20, 0, 201, 21))
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(18)
self.landuse_label.setFont(font)
self.landuse_label.setLayoutDirection(QtCore.Qt.LeftToRight)
self.landuse_label.setMidLineWidth(0)
self.landuse_label.setObjectName("landuse_label")
self.increase_label = QtWidgets.QLabel(self.groupBox)
self.increase_label.setGeometry(QtCore.QRect(20, 210, 201, 21))
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(18)
self.increase_label.setFont(font)
self.increase_label.setLayoutDirection(QtCore.Qt.LeftToRight)
self.increase_label.setMidLineWidth(0)
self.increase_label.setObjectName("increase_label")
self.rainfall_value = QtWidgets.QDoubleSpinBox(self.groupBox)
self.rainfall_value.setGeometry(QtCore.QRect(50, 240, 110, 24))
self.rainfall_value.setDecimals(1)
self.rainfall_value.setSingleStep(1.0)
self.rainfall_value.setObjectName("rainfall_value")
self.layoutWidget_9 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_9.setGeometry(QtCore.QRect(0, 170, 234, 26))
self.layoutWidget_9.setObjectName("layoutWidget_9")
self.horizontalLayout_6 = QtWidgets.QHBoxLayout(self.layoutWidget_9)
self.horizontalLayout_6.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_6.setObjectName("horizontalLayout_6")
# Here is the code for the LCD Number
# -----------------------------------------------------------
self.total_label = QtWidgets.QLabel(self.layoutWidget_9)
font = QtGui.QFont()
font.setPointSize(12)
self.total_label.setFont(font)
self.total_label.setObjectName("total_label")
self.horizontalLayout_6.addWidget(self.total_label)
self.total_sum = QtWidgets.QLCDNumber(self.layoutWidget_9)
font = QtGui.QFont()
font.setPointSize(10)
self.total_sum.setFont(font)
self.total_sum.setSegmentStyle(QtWidgets.QLCDNumber.Flat)
self.total_sum.setProperty("value", 0.0)
self.total_sum.setObjectName("total_sum")
self.horizontalLayout_6.addWidget(self.total_sum)
# -----------------------------------------------------------
self.layoutWidget_10 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_10.setGeometry(QtCore.QRect(0, 20, 234, 26))
self.layoutWidget_10.setObjectName("layoutWidget_10")
self.horizontalLayout_7 = QtWidgets.QHBoxLayout(self.layoutWidget_10)
self.horizontalLayout_7.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_7.setObjectName("horizontalLayout_7")
self.urban_label = QtWidgets.QLabel(self.layoutWidget_10)
font = QtGui.QFont()
font.setPointSize(12)
self.urban_label.setFont(font)
self.urban_label.setObjectName("urban_label")
self.horizontalLayout_7.addWidget(self.urban_label)
self.urban_value = QtWidgets.QDoubleSpinBox(self.layoutWidget_10)
self.urban_value.setSingleStep(0.05)
self.urban_value.setObjectName("urban_value")
self.horizontalLayout_7.addWidget(self.urban_value)
self.powered_by_label = QtWidgets.QLabel(self.tab)
self.powered_by_label.setGeometry(QtCore.QRect(460, 570, 111, 16))
font = QtGui.QFont()
font.setPointSize(11)
self.powered_by_label.setFont(font)
self.powered_by_label.setObjectName("powered_by_label")
self.landuse_label_2 = QtWidgets.QLabel(self.tab)
self.landuse_label_2.setGeometry(QtCore.QRect(330, 10, 421, 21))
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(18)
self.landuse_label_2.setFont(font)
self.landuse_label_2.setLayoutDirection(QtCore.Qt.LeftToRight)
self.landuse_label_2.setMidLineWidth(0)
self.landuse_label_2.setObjectName("landuse_label_2")
self.hydrograph_widget = QtWidgets.QGroupBox(self.tab)
self.hydrograph_widget.setGeometry(QtCore.QRect(280, 60, 711, 501))
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(14)
self.hydrograph_widget.setFont(font)
self.hydrograph_widget.setObjectName("hydrograph_widget")
self.plot_widget = QtWidgets.QWidget(self.hydrograph_widget)
self.plot_widget.setGeometry(QtCore.QRect(10, 30, 691, 461))
self.plot_widget.setObjectName("plot_widget")
self.tabWidget.addTab(self.tab, "")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1039, 22))
self.menubar.setObjectName("menubar")
self.menuMenu = QtWidgets.QMenu(self.menubar)
self.menuMenu.setObjectName("menuMenu")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.actionClose = QtWidgets.QAction(MainWindow)
self.actionClose.setCheckable(False)
self.actionClose.setObjectName("actionClose")
self.menuMenu.addAction(self.actionClose)
self.menubar.addAction(self.menuMenu.menuAction())
self.retranslateUi(MainWindow)
self.tabWidget.setCurrentIndex(0)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
MainWindow.setTabOrder(self.urban_value, self.grass_value)
MainWindow.setTabOrder(self.grass_value, self.arab_value)
MainWindow.setTabOrder(self.arab_value, self.wood_value)
MainWindow.setTabOrder(self.wood_value, self.mount_value)
MainWindow.setTabOrder(self.mount_value, self.rainfall_value)
MainWindow.setTabOrder(self.rainfall_value, self.start_butt)
MainWindow.setTabOrder(self.start_butt, self.tabWidget)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.grass_label.setText(_translate("MainWindow", "Grassland"))
self.arable_label.setText(_translate("MainWindow", "Arable"))
self.woodl_label.setText(_translate("MainWindow", "Woodland"))
self.mount_label.setText(_translate("MainWindow", "Mountain"))
self.start_butt.setText(_translate("MainWindow", "Start"))
self.landuse_label.setText(_translate("MainWindow", "Land Use Coverage (%)"))
self.increase_label.setText(_translate("MainWindow", "Increase in Rainfall (%)"))
self.total_label.setText(_translate("MainWindow", "Total"))
self.urban_label.setText(_translate("MainWindow", "Urban"))
self.powered_by_label.setText(_translate("MainWindow", "Powered by Group 1"))
self.landuse_label_2.setText(_translate("MainWindow", "Hydrological Modelling for the Ouseburn Catchment"))
self.hydrograph_widget.setTitle(_translate("MainWindow", "Hydrograph"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("MainWindow", "HydroModel v.1.0"))
self.menuMenu.setTitle(_translate("MainWindow", "Menu"))
self.actionClose.setText(_translate("MainWindow", "Close"))
#---------------------------------------------------------------------
# Here is my code for updating the LCDNumber
def all_inputs(self):
urban_inp = self.urban_value.value()
grass_inp = self.grass_value.value()
arab_inp = self.arab_value.value()
wood_inp = self.wood_value.value()
mount_inp = self.mount_value.value()
total = urban_inp + grass_inp + arab_inp + wood_inp + mount_inp
self.total_sum.display(total)
#---------------------------------------------------------------------
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_())

QDoubleSpinBox::valueChanged(double d)
This signal is emitted whenever the spin box's value is changed.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1039, 654)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.tabWidget = QtWidgets.QTabWidget(self.centralwidget)
self.tabWidget.setGeometry(QtCore.QRect(10, 0, 1001, 621))
self.tabWidget.setObjectName("tabWidget")
self.tab = QtWidgets.QWidget()
self.tab.setObjectName("tab")
self.groupBox = QtWidgets.QGroupBox(self.tab)
self.groupBox.setGeometry(QtCore.QRect(10, 40, 241, 521))
font = QtGui.QFont()
font.setPointSize(11)
self.groupBox.setFont(font)
self.groupBox.setTitle("")
self.groupBox.setObjectName("groupBox")
self.layoutWidget_5 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_5.setGeometry(QtCore.QRect(0, 50, 234, 26))
self.layoutWidget_5.setObjectName("layoutWidget_5")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.layoutWidget_5)
self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.grass_label = QtWidgets.QLabel(self.layoutWidget_5)
font = QtGui.QFont()
font.setPointSize(12)
self.grass_label.setFont(font)
self.grass_label.setObjectName("grass_label")
self.horizontalLayout_2.addWidget(self.grass_label)
self.grass_value = QtWidgets.QDoubleSpinBox(self.layoutWidget_5)
self.grass_value.setSingleStep(0.05)
self.grass_value.setObjectName("grass_value")
self.horizontalLayout_2.addWidget(self.grass_value)
self.layoutWidget_6 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_6.setGeometry(QtCore.QRect(0, 80, 234, 26))
self.layoutWidget_6.setObjectName("layoutWidget_6")
self.horizontalLayout_3 = QtWidgets.QHBoxLayout(self.layoutWidget_6)
self.horizontalLayout_3.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.arable_label = QtWidgets.QLabel(self.layoutWidget_6)
font = QtGui.QFont()
font.setPointSize(12)
self.arable_label.setFont(font)
self.arable_label.setObjectName("arable_label")
self.horizontalLayout_3.addWidget(self.arable_label)
self.arab_value = QtWidgets.QDoubleSpinBox(self.layoutWidget_6)
self.arab_value.setSingleStep(0.05)
self.arab_value.setObjectName("arab_value")
self.horizontalLayout_3.addWidget(self.arab_value)
self.layoutWidget_7 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_7.setGeometry(QtCore.QRect(0, 110, 234, 26))
self.layoutWidget_7.setObjectName("layoutWidget_7")
self.horizontalLayout_4 = QtWidgets.QHBoxLayout(self.layoutWidget_7)
self.horizontalLayout_4.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.woodl_label = QtWidgets.QLabel(self.layoutWidget_7)
font = QtGui.QFont()
font.setPointSize(12)
self.woodl_label.setFont(font)
self.woodl_label.setObjectName("woodl_label")
self.horizontalLayout_4.addWidget(self.woodl_label)
self.wood_value = QtWidgets.QDoubleSpinBox(self.layoutWidget_7)
self.wood_value.setSingleStep(0.05)
self.wood_value.setObjectName("wood_value")
self.horizontalLayout_4.addWidget(self.wood_value)
self.layoutWidget_8 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_8.setGeometry(QtCore.QRect(0, 140, 234, 26))
self.layoutWidget_8.setObjectName("layoutWidget_8")
self.horizontalLayout_5 = QtWidgets.QHBoxLayout(self.layoutWidget_8)
self.horizontalLayout_5.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_5.setObjectName("horizontalLayout_5")
self.mount_label = QtWidgets.QLabel(self.layoutWidget_8)
font = QtGui.QFont()
font.setPointSize(12)
self.mount_label.setFont(font)
self.mount_label.setObjectName("mount_label")
self.horizontalLayout_5.addWidget(self.mount_label)
self.mount_value = QtWidgets.QDoubleSpinBox(self.layoutWidget_8)
self.mount_value.setSingleStep(0.05)
self.mount_value.setObjectName("mount_value")
self.horizontalLayout_5.addWidget(self.mount_value)
self.start_butt = QtWidgets.QPushButton(self.groupBox)
self.start_butt.setGeometry(QtCore.QRect(50, 290, 113, 32))
self.start_butt.setObjectName("start_butt")
self.landuse_label = QtWidgets.QLabel(self.groupBox)
self.landuse_label.setGeometry(QtCore.QRect(20, 0, 201, 21))
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(18)
self.landuse_label.setFont(font)
self.landuse_label.setLayoutDirection(QtCore.Qt.LeftToRight)
self.landuse_label.setMidLineWidth(0)
self.landuse_label.setObjectName("landuse_label")
self.increase_label = QtWidgets.QLabel(self.groupBox)
self.increase_label.setGeometry(QtCore.QRect(20, 210, 201, 21))
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(18)
self.increase_label.setFont(font)
self.increase_label.setLayoutDirection(QtCore.Qt.LeftToRight)
self.increase_label.setMidLineWidth(0)
self.increase_label.setObjectName("increase_label")
self.rainfall_value = QtWidgets.QDoubleSpinBox(self.groupBox)
self.rainfall_value.setGeometry(QtCore.QRect(50, 240, 110, 24))
self.rainfall_value.setDecimals(1)
self.rainfall_value.setSingleStep(1.0)
self.rainfall_value.setObjectName("rainfall_value")
self.layoutWidget_9 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_9.setGeometry(QtCore.QRect(0, 170, 234, 26))
self.layoutWidget_9.setObjectName("layoutWidget_9")
self.horizontalLayout_6 = QtWidgets.QHBoxLayout(self.layoutWidget_9)
self.horizontalLayout_6.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_6.setObjectName("horizontalLayout_6")
# Here is the code for the LCD Number
# -----------------------------------------------------------
self.total_label = QtWidgets.QLabel(self.layoutWidget_9)
font = QtGui.QFont()
font.setPointSize(12)
self.total_label.setFont(font)
self.total_label.setObjectName("total_label")
self.horizontalLayout_6.addWidget(self.total_label)
self.total_sum = QtWidgets.QLCDNumber(self.layoutWidget_9)
font = QtGui.QFont()
font.setPointSize(10)
self.total_sum.setFont(font)
self.total_sum.setSegmentStyle(QtWidgets.QLCDNumber.Flat)
self.total_sum.setProperty("value", 0.0)
self.total_sum.setObjectName("total_sum")
self.horizontalLayout_6.addWidget(self.total_sum)
# -----------------------------------------------------------
self.layoutWidget_10 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_10.setGeometry(QtCore.QRect(0, 20, 234, 26))
self.layoutWidget_10.setObjectName("layoutWidget_10")
self.horizontalLayout_7 = QtWidgets.QHBoxLayout(self.layoutWidget_10)
self.horizontalLayout_7.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_7.setObjectName("horizontalLayout_7")
self.urban_label = QtWidgets.QLabel(self.layoutWidget_10)
font = QtGui.QFont()
font.setPointSize(12)
self.urban_label.setFont(font)
self.urban_label.setObjectName("urban_label")
self.horizontalLayout_7.addWidget(self.urban_label)
self.urban_value = QtWidgets.QDoubleSpinBox(self.layoutWidget_10)
self.urban_value.setSingleStep(0.05)
self.urban_value.setObjectName("urban_value")
self.horizontalLayout_7.addWidget(self.urban_value)
self.powered_by_label = QtWidgets.QLabel(self.tab)
self.powered_by_label.setGeometry(QtCore.QRect(460, 570, 111, 16))
font = QtGui.QFont()
font.setPointSize(11)
self.powered_by_label.setFont(font)
self.powered_by_label.setObjectName("powered_by_label")
self.landuse_label_2 = QtWidgets.QLabel(self.tab)
self.landuse_label_2.setGeometry(QtCore.QRect(330, 10, 421, 21))
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(18)
self.landuse_label_2.setFont(font)
self.landuse_label_2.setLayoutDirection(QtCore.Qt.LeftToRight)
self.landuse_label_2.setMidLineWidth(0)
self.landuse_label_2.setObjectName("landuse_label_2")
self.hydrograph_widget = QtWidgets.QGroupBox(self.tab)
self.hydrograph_widget.setGeometry(QtCore.QRect(280, 60, 711, 501))
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(14)
self.hydrograph_widget.setFont(font)
self.hydrograph_widget.setObjectName("hydrograph_widget")
self.plot_widget = QtWidgets.QWidget(self.hydrograph_widget)
self.plot_widget.setGeometry(QtCore.QRect(10, 30, 691, 461))
self.plot_widget.setObjectName("plot_widget")
self.tabWidget.addTab(self.tab, "")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1039, 22))
self.menubar.setObjectName("menubar")
self.menuMenu = QtWidgets.QMenu(self.menubar)
self.menuMenu.setObjectName("menuMenu")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.actionClose = QtWidgets.QAction(MainWindow)
self.actionClose.setCheckable(False)
self.actionClose.setObjectName("actionClose")
self.menuMenu.addAction(self.actionClose)
self.menubar.addAction(self.menuMenu.menuAction())
self.retranslateUi(MainWindow)
self.tabWidget.setCurrentIndex(0)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
MainWindow.setTabOrder(self.urban_value, self.grass_value)
MainWindow.setTabOrder(self.grass_value, self.arab_value)
MainWindow.setTabOrder(self.arab_value, self.wood_value)
MainWindow.setTabOrder(self.wood_value, self.mount_value)
MainWindow.setTabOrder(self.mount_value, self.rainfall_value)
MainWindow.setTabOrder(self.rainfall_value, self.start_butt)
MainWindow.setTabOrder(self.start_butt, self.tabWidget)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.grass_label.setText(_translate("MainWindow", "Grassland"))
self.arable_label.setText(_translate("MainWindow", "Arable"))
self.woodl_label.setText(_translate("MainWindow", "Woodland"))
self.mount_label.setText(_translate("MainWindow", "Mountain"))
self.start_butt.setText(_translate("MainWindow", "Start"))
self.landuse_label.setText(_translate("MainWindow", "Land Use Coverage (%)"))
self.increase_label.setText(_translate("MainWindow", "Increase in Rainfall (%)"))
self.total_label.setText(_translate("MainWindow", "Total"))
self.urban_label.setText(_translate("MainWindow", "Urban"))
self.powered_by_label.setText(_translate("MainWindow", "Powered by Group 1"))
self.landuse_label_2.setText(_translate("MainWindow", "Hydrological Modelling for the Ouseburn Catchment"))
self.hydrograph_widget.setTitle(_translate("MainWindow", "Hydrograph"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("MainWindow", "HydroModel v.1.0"))
self.menuMenu.setTitle(_translate("MainWindow", "Menu"))
self.actionClose.setText(_translate("MainWindow", "Close"))
class Example(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self):
super(Example, self).__init__()
self.setupUi(self)
self.urban_value.valueChanged.connect(self.all_inputs) # +
self.grass_value.valueChanged.connect(self.all_inputs) # +
self.arab_value.valueChanged.connect(self.all_inputs) # +
self.wood_value.valueChanged.connect(self.all_inputs) # +
self.mount_value.valueChanged.connect(self.all_inputs) # +
# Here is my code for updating the LCDNumber
def all_inputs(self):
urban_inp = self.urban_value.value()
grass_inp = self.grass_value.value()
arab_inp = self.arab_value.value()
wood_inp = self.wood_value.value()
mount_inp = self.mount_value.value()
total = urban_inp + grass_inp + arab_inp + wood_inp + mount_inp
self.total_sum.display(total)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
w = Example()
w.show()
sys.exit(app.exec_())

Related

pyqt5 QMessageBox TypeError [duplicate]

This question already has answers here:
QtDesigner changes will be lost after redesign User Interface
(2 answers)
Closed 11 months ago.
i was wondering if it possible using QMessagBox in Qmainwindow.
i am getting this error:
Traceback (most recent call last): File
"C:\Users\royqb\desktop\python_learning\softwaremgmt\table.py", line
229, in refresh_warning
msg.question(self,'Warning', 'Are you sure to continue?',msg.Yes | msg.No) TypeError: question(QWidget, str, str, buttons:
Union[QMessageBox.StandardButtons, QMessageBox.StandardButton] =
QMessageBox.StandardButtons(QMessageBox.Yes|QMessageBox.No),
defaultButton: QMessageBox.StandardButton = QMessageBox.NoButton):
argument 1 has unexpected type 'Ui_MainWindow'
in other window which is Qdialog it works just fine.
please help :)
import sqlite3
import smtplib
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtSql import *
from PyQt5.QtGui import *
from newlogin import *
class Ui_MainWindow(object):
# def __init__(self):
# self.connect = sqlite3.connect('lics.db')
# self.cur = self.connect.cursor()
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.setEnabled(True)
# MainWindow.resize(1250, 800)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
# self.setWindowTitle('Licenses')
self.new_lic_button = QtWidgets.QPushButton(self.centralwidget)
self.new_lic_button.setGeometry(QtCore.QRect(10, 80, 150, 40))
self.new_lic_button.setStyleSheet("QPushButton#new_lic_button{\n"
"background-color:lightgrey;\n"
"border-radius:5px;\n"
"color:grey;\n"
"border:1px solid darkgrey;\n"
"}\n"
"QPushButton#new_lic_button:pressed{\n"
"background-color:rgba(148, 151, 150, 0.8);\n"
"}\n"
"QPushButton#new_lic_button:hover{\n"
"background-color:rgba(223, 223, 223, 0.8);\n"
"color:rgba(89, 93, 92, 0.8);\n"
"}\n"
"")
self.new_lic_button.setObjectName("ref_data")
self.send_mail_button = QtWidgets.QPushButton(self.centralwidget)
self.send_mail_button.setGeometry(QtCore.QRect(170, 80, 150, 40))
self.send_mail_button.setStyleSheet("QPushButton#send_mail_button{\n"
"background-color:lightgrey;\n"
"border-radius:5px;\n"
"color:grey;\n"
"border:1px solid darkgrey;\n"
"}\n"
"QPushButton#send_mail_button:pressed{\n"
"background-color:rgba(148, 151, 150, 0.8);\n"
"}\n"
"QPushButton#send_mail_button:hover{\n"
"background-color:rgba(223, 223, 223, 0.8);\n"
"color:rgba(89, 93, 92, 0.8);\n"
"}\n"
"")
self.send_mail_button.setObjectName("sub_change")
self.tableWidget = QtWidgets.QTableWidget(self.centralwidget)
self.tableWidget.setGeometry(QtCore.QRect(10, 150, 1700, 900))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.tableWidget.sizePolicy().hasHeightForWidth())
self.tableWidget.setSizePolicy(sizePolicy)
self.tableWidget.setStyleSheet("background-color:rgba(246, 246, 246, 0.8)")
self.tableWidget.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.tableWidget.setFrameShadow(QtWidgets.QFrame.Sunken)
self.tableWidget.setLineWidth(1)
self.tableWidget.setWordWrap(True)
self.tableWidget.setRowCount(0)
self.tableWidget.setObjectName("tableWidget")
self.tableWidget.setColumnCount(8)
item = QtWidgets.QTableWidgetItem()
font = QtGui.QFont()
font.setPointSize(8)
font.setBold(True)
font.setWeight(75)
item.setFont(font)
item.setBackground(QtGui.QColor(230, 230, 230))
self.tableWidget.setHorizontalHeaderItem(0, item)
item = QtWidgets.QTableWidgetItem()
font = QtGui.QFont()
font.setPointSize(8)
font.setBold(True)
font.setWeight(75)
item.setFont(font)
item.setBackground(QtGui.QColor(230, 230, 230))
self.tableWidget.setHorizontalHeaderItem(1, item)
item = QtWidgets.QTableWidgetItem()
font = QtGui.QFont()
font.setPointSize(8)
font.setBold(True)
font.setWeight(75)
item.setFont(font)
item.setBackground(QtGui.QColor(230, 230, 230))
self.tableWidget.setHorizontalHeaderItem(2, item)
item = QtWidgets.QTableWidgetItem()
font = QtGui.QFont()
font.setPointSize(8)
font.setBold(True)
font.setWeight(75)
item.setFont(font)
item.setBackground(QtGui.QColor(230, 230, 230))
self.tableWidget.setHorizontalHeaderItem(3, item)
item = QtWidgets.QTableWidgetItem()
font = QtGui.QFont()
font.setPointSize(8)
font.setBold(True)
font.setWeight(75)
item.setFont(font)
item.setBackground(QtGui.QColor(230, 230, 230))
self.tableWidget.setHorizontalHeaderItem(4, item)
item = QtWidgets.QTableWidgetItem()
font = QtGui.QFont()
font.setPointSize(8)
font.setBold(True)
font.setWeight(75)
item.setFont(font)
item.setBackground(QtGui.QColor(230, 230, 230))
self.tableWidget.setHorizontalHeaderItem(5, item)
item = QtWidgets.QTableWidgetItem()
font = QtGui.QFont()
font.setPointSize(8)
font.setBold(True)
font.setWeight(75)
item.setFont(font)
self.tableWidget.setHorizontalHeaderItem(6, item)
item = QtWidgets.QTableWidgetItem()
font = QtGui.QFont()
font.setPointSize(8)
font.setBold(True)
font.setWeight(75)
item.setFont(font)
self.tableWidget.setHorizontalHeaderItem(7, item)
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(750, 10, 280, 51))
font = QtGui.QFont()
font.setFamily("Segoe script")
font.setPointSize(10)
self.label.setFont(font)
self.label.setStyleSheet("text-size:20px;")
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.label.setObjectName("label")
self.widget = QtWidgets.QWidget(self.centralwidget)
self.widget.setGeometry(QtCore.QRect(0, 0, 1920, 1000))
self.widget.setStyleSheet("border-radius:20px;\n"
"background-color:rgb(187, 247, 228,0.8);")
self.widget.setObjectName("widget")
self.widget.raise_()
self.new_lic_button.raise_()
self.send_mail_button.raise_()
self.tableWidget.raise_()
self.label.raise_()
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1016, 22))
self.menubar.setObjectName("menubar")
self.menuFile = QtWidgets.QMenu(self.menubar)
self.menuFile.setObjectName("menuFile")
self.menuEfit = QtWidgets.QMenu(self.menubar)
self.menuEfit.setObjectName("menuEfit")
MainWindow.setMenuBar(self.menubar)
self.toolBar = QtWidgets.QToolBar(MainWindow)
self.toolBar.setObjectName("toolBar")
MainWindow.addToolBar(QtCore.Qt.LeftToolBarArea, self.toolBar)
self.actionShow_All = QtWidgets.QAction(MainWindow)
icon3 = QtGui.QIcon()
icon3.addPixmap(QtGui.QPixmap("pic/icons/show.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.actionShow_All.setIcon(icon3)
self.actionShow_All.setObjectName("actionShow_All")
self.actionExport_xlsx = QtWidgets.QAction(MainWindow)
self.actionExport_xlsx.setObjectName("actionExport_xlsx")
self.actionExport_Xlsx = QtWidgets.QAction(MainWindow)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("pic/icons/xlsx.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.actionExport_Xlsx.setIcon(icon)
self.actionExport_Xlsx.setObjectName("actionExport_Xlsx")
self.actionEmail = QtWidgets.QAction(MainWindow)
icon1 = QtGui.QIcon()
icon1.addPixmap(QtGui.QPixmap("pic/icons/mail.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.actionEmail.setIcon(icon1)
self.actionEmail.setObjectName("actionEmail")
self.actionNew_License = QtWidgets.QAction(MainWindow)
icon2 = QtGui.QIcon()
icon2.addPixmap(QtGui.QPixmap("pic/icons/plus.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.actionNew_License.setIcon(icon2)
self.actionNew_License.setObjectName("actionNew_License")
self.menuFile.addAction(self.actionExport_xlsx)
self.menubar.addAction(self.menuFile.menuAction())
self.menubar.addAction(self.menuEfit.menuAction())
self.toolBar.addAction(self.actionNew_License)
self.toolBar.addAction(self.actionExport_Xlsx)
self.toolBar.addAction(self.actionEmail)
self.toolBar.addAction(self.actionShow_All)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
#send mail from tool bar
self.actionEmail.triggered.connect(self.send_mail)
#table width
MainWindow.setGeometry(QtCore.QRect(10, 100, 1920, 900))
self.tableWidget.setColumnWidth(0, 180)
self.tableWidget.setColumnWidth(1, 250)
self.tableWidget.setColumnWidth(2, 250)
self.tableWidget.setColumnWidth(3, 100)
self.tableWidget.setColumnWidth(4, 150)
self.tableWidget.setColumnWidth(5, 150)
self.tableWidget.setColumnWidth(6, 100)
self.tableWidget.setColumnWidth(7, 500)
self.tableWidget.setHorizontalHeaderLabels(
['Company', 'License type', 'Supplier', 'Interval', 'Last update', 'Next update', 'Time left'])
self.loaddata()
self.new_lic_button.clicked.connect(self.refresh_warning)
# self.send_mail_button.clicked.connect(self.submit_changes)
def refresh_warning(self):
msg = QMessageBox()
# msg.setWindowTitle(self,"Warning")
# msg.setText(self, 'Any changes you made will be lost!')
msg.question(self,'Warning', 'Are you sure to continue?',msg.Yes | msg.No)
msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
msg.exec_()
if self.new_lic_button.clicked:
ask = MainWindow.QMessageBox.question(MainWindow,"If you made changes they will be lost! \nUse 'Submit Changes' button to save your changes, continue?",QMessageBox.Yes|QMessageBox.No)
if ask == QMessageBox.Yes:
self.loaddata()
def loaddata(self):
connect = sqlite3.connect('lics.db')
cur = connect.cursor()
sqlquery = ('select company,lic_name,supplier, frequency,last_update, next_update, time_left, lic_path from licenses WHERE time_left_int < 30 order by time_left_int asc ')
cur.execute(sqlquery)
rows = cur.fetchall()
self.tableWidget.setRowCount(len(rows))
tablerow = 0
for row in cur.execute(sqlquery):
self.tableWidget.setItem(tablerow, 0, QtWidgets.QTableWidgetItem(row[0]))
self.tableWidget.setItem(tablerow, 1, QtWidgets.QTableWidgetItem(row[1]))
self.tableWidget.setItem(tablerow, 2, QtWidgets.QTableWidgetItem(row[2]))
self.tableWidget.setItem(tablerow, 3, QtWidgets.QTableWidgetItem(row[3]))
self.tableWidget.setItem(tablerow, 4, QtWidgets.QTableWidgetItem(row[4]))
self.tableWidget.setItem(tablerow, 5, QtWidgets.QTableWidgetItem(row[5]))
self.tableWidget.setItem(tablerow, 6, QtWidgets.QTableWidgetItem(row[6]))
self.tableWidget.setItem(tablerow, 7, QtWidgets.QTableWidgetItem(row[7]))
tablerow +=1
def send_mail(self):
self.ui2 = Ui_login_page()
user = self.ui2.hashed_user
# print(user)
connect = sqlite3.connect('lics.db')
cur = connect.cursor()
# emailsql = ("select email from users where user = '{}' ".format(user))
# print(emailsql)
smtp_sslobj = smtplib.SMTP_SSL('smtp.gmail.com',465)
smtp_sslobj.ehlo()
# smtp_sslobj.starttls()
sent_from = "pythroy#gmail.com"
# self.to_mail = ""
gmail_user = sent_from
sqlq= ('select email_pass from users where email = "{}" '.format(self.to_mail))
gmail_pass = '1qa1qa1qa'
# cur.execute(sqlq)
# print(gmail_pass)
smtp_sslobj.login(sent_from,gmail_pass)
to = self.to_mail
subject ="Expiring licenses"
body = "hello"
smtp_sslobj.sendmail(sent_from, self.to_mail,"hello" )
smtp_sslobj.close()
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.new_lic_button.setText(_translate("MainWindow", "Refresh Data"))
self.send_mail_button.setText(_translate("MainWindow", "Submit Changes"))
self.tableWidget.setSortingEnabled(True)
item = self.tableWidget.horizontalHeaderItem(0)
item.setText(_translate("MainWindow", "Company"))
item = self.tableWidget.horizontalHeaderItem(1)
item.setText(_translate("MainWindow", "Lic name"))
item = self.tableWidget.horizontalHeaderItem(2)
item.setText(_translate("MainWindow", "Supplier"))
item = self.tableWidget.horizontalHeaderItem(3)
item.setText(_translate("MainWindow", "Interval"))
item = self.tableWidget.horizontalHeaderItem(4)
item.setText(_translate("MainWindow", "Last update"))
item = self.tableWidget.horizontalHeaderItem(5)
item.setText(_translate("MainWindow", "Next update"))
item = self.tableWidget.horizontalHeaderItem(6)
item.setText(_translate("MainWindow", "Time left"))
item = self.tableWidget.horizontalHeaderItem(7)
item.setText(_translate("MainWindow", "Path"))
self.label.setText(_translate("MainWindow", "<html><head/><body><p align=\"center\"><span style=\" font-size:14pt; font-weight:600; text-decoration: underline;\">Expiring Licenses</span></p></body></html>"))
self.menuFile.setTitle(_translate("MainWindow", "File"))
self.menuEfit.setTitle(_translate("MainWindow", "Edit"))
self.toolBar.setWindowTitle(_translate("MainWindow", "toolBar"))
self.actionExport_xlsx.setText(_translate("MainWindow", "Export xlsx"))
self.actionExport_Xlsx.setText(_translate("MainWindow", "Export Xlsx"))
self.actionExport_Xlsx.setToolTip(_translate("MainWindow", "Export to xlsx"))
self.actionExport_Xlsx.setStatusTip(_translate("MainWindow", "Export to xlsx"))
self.actionEmail.setText(_translate("MainWindow", "Email"))
self.actionEmail.setToolTip(_translate("MainWindow", "Send mail"))
self.actionEmail.setStatusTip(_translate("MainWindow", "Send mail"))
self.actionNew_License.setText(_translate("MainWindow", "New License"))
self.actionNew_License.setStatusTip(_translate("MainWindow", "Insert new license"))
self.actionNew_License.setWhatsThis(_translate("MainWindow", "New license"))
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_())
QMessageBox.questions first argument must be QWidget or None, Ui_MainWindow (self) is not a widget, it's a helper class not inherited from QWidget, use self.widget instead.

Stretch Axis to Fit Graphics View QT Designer

I am trying to get the x axis to fill the entire of the graphics view.
What I have now (the x axis stops around two thirds of the way of the graphics view:
what I am trying to acheive:
I have tried plot.setXRange() with zero padding but that just changes the x axis limits.
I am also unsure about why I cannot see the origin (the x and y axis does not intercept)
Just in case, here is the generated python file from QT designer.ui:
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1131, 890)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.labelCh1 = QtWidgets.QLabel(self.centralwidget)
self.labelCh1.setGeometry(QtCore.QRect(10, 100, 31, 51))
self.labelCh1.setObjectName("labelCh1")
self.labelCh2 = QtWidgets.QLabel(self.centralwidget)
self.labelCh2.setGeometry(QtCore.QRect(10, 190, 31, 51))
self.labelCh2.setObjectName("labelCh2")
self.labelCh3 = QtWidgets.QLabel(self.centralwidget)
self.labelCh3.setGeometry(QtCore.QRect(10, 290, 31, 51))
self.labelCh3.setObjectName("labelCh3")
self.layoutWidget = QtWidgets.QWidget(self.centralwidget)
self.layoutWidget.setGeometry(QtCore.QRect(50, 80, 1051, 747))
self.layoutWidget.setObjectName("layoutWidget")
self.gridLayout = QtWidgets.QGridLayout(self.layoutWidget)
self.gridLayout.setSizeConstraint(QtWidgets.QLayout.SetDefaultConstraint)
self.gridLayout.setContentsMargins(0, 0, 0, 0)
self.gridLayout.setHorizontalSpacing(0)
self.gridLayout.setVerticalSpacing(7)
self.gridLayout.setObjectName("gridLayout")
self.PlotWidgetCh6 = PlotWidget(self.layoutWidget)
self.PlotWidgetCh6.setObjectName("PlotWidgetCh6")
self.gridLayout.addWidget(self.PlotWidgetCh6, 5, 0, 1, 1)
self.PlotWidgetCh5 = PlotWidget(self.layoutWidget)
self.PlotWidgetCh5.setObjectName("PlotWidgetCh5")
self.gridLayout.addWidget(self.PlotWidgetCh5, 4, 0, 1, 1)
self.PlotWidgetCh2 = PlotWidget(self.layoutWidget)
self.PlotWidgetCh2.setObjectName("PlotWidgetCh2")
self.gridLayout.addWidget(self.PlotWidgetCh2, 1, 0, 1, 1)
self.PlotWidgetCh7 = PlotWidget(self.layoutWidget)
self.PlotWidgetCh7.setObjectName("PlotWidgetCh7")
self.gridLayout.addWidget(self.PlotWidgetCh7, 6, 0, 1, 1)
self.PlotWidgetCh1 = PlotWidget(self.layoutWidget)
self.PlotWidgetCh1.setObjectName("PlotWidgetCh1")
self.gridLayout.addWidget(self.PlotWidgetCh1, 0, 0, 1, 1)
self.PlotWidgetCh3 = PlotWidget(self.layoutWidget)
self.PlotWidgetCh3.setObjectName("PlotWidgetCh3")
self.gridLayout.addWidget(self.PlotWidgetCh3, 2, 0, 1, 1)
self.PlotWidgetCh4 = PlotWidget(self.layoutWidget)
self.PlotWidgetCh4.setObjectName("PlotWidgetCh4")
self.gridLayout.addWidget(self.PlotWidgetCh4, 3, 0, 1, 1)
self.PlotWidgetCh8 = PlotWidget(self.layoutWidget)
self.PlotWidgetCh8.setObjectName("PlotWidgetCh8")
self.gridLayout.addWidget(self.PlotWidgetCh8, 7, 0, 1, 1)
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(10, 0, 81, 71))
self.label.setText("")
self.label.setPixmap(QtGui.QPixmap("../OneDrive - AB Dynamics Ltd/Desktop/brainpatch3.png"))
self.label.setObjectName("label")
self.labelCh3_2 = QtWidgets.QLabel(self.centralwidget)
self.labelCh3_2.setGeometry(QtCore.QRect(10, 380, 31, 51))
self.labelCh3_2.setObjectName("labelCh3_2")
self.labelCh3_3 = QtWidgets.QLabel(self.centralwidget)
self.labelCh3_3.setGeometry(QtCore.QRect(10, 480, 31, 51))
self.labelCh3_3.setObjectName("labelCh3_3")
self.labelCh3_4 = QtWidgets.QLabel(self.centralwidget)
self.labelCh3_4.setGeometry(QtCore.QRect(10, 570, 31, 51))
self.labelCh3_4.setObjectName("labelCh3_4")
self.labelCh3_5 = QtWidgets.QLabel(self.centralwidget)
self.labelCh3_5.setGeometry(QtCore.QRect(10, 660, 31, 51))
self.labelCh3_5.setObjectName("labelCh3_5")
self.labelCh3_6 = QtWidgets.QLabel(self.centralwidget)
self.labelCh3_6.setGeometry(QtCore.QRect(10, 760, 31, 51))
self.labelCh3_6.setObjectName("labelCh3_6")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(980, 10, 111, 51))
self.pushButton.setObjectName("pushButton")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(710, 10, 201, 51))
font = QtGui.QFont()
font.setPointSize(12)
self.label_2.setFont(font)
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(10, 0, 81, 71))
self.label_3.setText("")
self.label_3.setPixmap(QtGui.QPixmap("logo.png"))
self.label_3.setObjectName("label_3")
self.numOfChBox = QtWidgets.QSpinBox(self.centralwidget)
self.numOfChBox.setGeometry(QtCore.QRect(920, 10, 51, 51))
font = QtGui.QFont()
font.setPointSize(16)
font.setBold(True)
font.setWeight(75)
self.numOfChBox.setFont(font)
self.numOfChBox.setObjectName("numOfChBox")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1131, 26))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.labelCh1.setText(_translate("MainWindow", "Ch 1"))
self.labelCh2.setText(_translate("MainWindow", "Ch 2"))
self.labelCh3.setText(_translate("MainWindow", "Ch 3"))
self.labelCh3_2.setText(_translate("MainWindow", "Ch 4"))
self.labelCh3_3.setText(_translate("MainWindow", "Ch 5"))
self.labelCh3_4.setText(_translate("MainWindow", "Ch 6"))
self.labelCh3_5.setText(_translate("MainWindow", "Ch 7"))
self.labelCh3_6.setText(_translate("MainWindow", "Ch 8"))
self.pushButton.setText(_translate("MainWindow", "Start/Stop"))
self.label_2.setText(_translate("MainWindow", "Number Of Channels:"))
from pyqtgraph import PlotWidget
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_())
Any suggestions much appreciated.
Thanks in advance,
Will

Not able to Configure Scroll Area in Pyqt5 Python

Complete Code
I am expecting a scroll bar should get auto populate so that user can see the rest of the item.
in that highlighted area I tried
created one widget
added one Scroll Area under that widget
add a from lay out under Scroll Area
adding items to that from layout.
but the scroll area is not working.
#!/usr/bin/python
# -*- coding: utf-8 -*-
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName('MainWindow')
MainWindow.resize(817, 588)
sizePolicy = \
QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred,
QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
MainWindow.setSizePolicy(sizePolicy)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName('centralwidget')
self.verticalLayoutWidget = \
QtWidgets.QWidget(self.centralwidget)
self.verticalLayoutWidget.setGeometry(QtCore.QRect(20, 40, 761,
60))
self.verticalLayoutWidget.setObjectName('verticalLayoutWidget')
self.verticalLayout = \
QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setObjectName('verticalLayout')
self.gridLayout = QtWidgets.QGridLayout()
self.gridLayout.setSizeConstraint(QtWidgets.QLayout.SetDefaultConstraint)
self.gridLayout.setObjectName('gridLayout')
self.label = QtWidgets.QLabel(self.verticalLayoutWidget)
self.label.setObjectName('label')
self.gridLayout.addWidget(
self.label,
0,
0,
1,
1,
QtCore.Qt.AlignLeft,
)
self.searchString = \
QtWidgets.QLineEdit(self.verticalLayoutWidget)
self.searchString.setMaximumSize(QtCore.QSize(673, 16777215))
self.searchString.setObjectName('searchString')
self.gridLayout.addWidget(self.searchString, 0, 1, 1, 1)
self.submit = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.submit.setObjectName('submit')
self.gridLayout.addWidget(self.submit, 0, 2, 1, 1)
self.verticalLayout.addLayout(self.gridLayout)
self.errorLabel = QtWidgets.QLabel(self.centralwidget)
self.errorLabel.setGeometry(QtCore.QRect(30, 10, 751, 16))
self.errorLabel.setText('')
self.errorLabel.setObjectName('errorLabel')
self.groupBox = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox.setGeometry(QtCore.QRect(40, 140, 361, 151))
self.groupBox.setObjectName('groupBox')
self.serverList = QtWidgets.QListWidget(self.groupBox)
self.serverList.setEnabled(True)
self.serverList.setGeometry(QtCore.QRect(10, 20, 331, 121))
self.serverList.setSelectionMode(QtWidgets.QAbstractItemView.MultiSelection)
self.serverList.setResizeMode(QtWidgets.QListView.Fixed)
self.serverList.setObjectName('serverList')
item = QtWidgets.QListWidgetItem()
self.serverList.addItem(item)
item = QtWidgets.QListWidgetItem()
self.serverList.addItem(item)
item = QtWidgets.QListWidgetItem()
self.serverList.addItem(item)
self.groupBox_2 = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox_2.setGeometry(QtCore.QRect(410, 140, 361, 151))
self.groupBox_2.setObjectName('groupBox_2')
self.autoDownload = QtWidgets.QCheckBox(self.groupBox_2)
self.autoDownload.setGeometry(QtCore.QRect(10, 30, 121, 20))
self.autoDownload.setObjectName('autoDownload')
self.specificFileFlag = QtWidgets.QCheckBox(self.groupBox_2)
self.specificFileFlag.setGeometry(QtCore.QRect(10, 60, 171, 20))
self.specificFileFlag.setObjectName('specificFileFlag')
self.downloadSelected = QtWidgets.QPushButton(self.groupBox_2)
self.downloadSelected.setGeometry(QtCore.QRect(10, 97, 141, 31))
self.downloadSelected.setObjectName('downloadSelected')
self.searchArchive = QtWidgets.QCheckBox(self.groupBox_2)
self.searchArchive.setGeometry(QtCore.QRect(170, 30, 141, 20))
self.searchArchive.setObjectName('searchArchive')
self.checkBox = QtWidgets.QCheckBox(self.groupBox_2)
self.checkBox.setGeometry(QtCore.QRect(170, 60, 191, 21))
self.checkBox.setObjectName('checkBox')
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(640, 540, 161, 20))
self.label_2.setObjectName('label_2')
self.selectedServer = QtWidgets.QLabel(self.centralwidget)
self.selectedServer.setGeometry(QtCore.QRect(30, 120, 751, 21))
self.selectedServer.setText('')
self.selectedServer.setObjectName('selectedServer')
self.widget = QtWidgets.QWidget(self.centralwidget)
self.widget.setGeometry(QtCore.QRect(30, 300, 761, 241))
self.widget.setObjectName('widget')
self.scrollArea = QtWidgets.QScrollArea(self.widget)
self.scrollArea.setGeometry(QtCore.QRect(9, 6, 731, 221))
self.scrollArea.setObjectName('scrollArea')
self.scrollAreaWidgetContents = QtWidgets.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0,
729, 219))
self.scrollAreaWidgetContents.setObjectName('scrollAreaWidgetContents'
)
self.formLayoutWidget = \
QtWidgets.QWidget(self.scrollAreaWidgetContents)
self.formLayoutWidget.setGeometry(QtCore.QRect(0, 1, 731, 221))
self.formLayoutWidget.setObjectName('formLayoutWidget')
self.formLayout = QtWidgets.QFormLayout(self.formLayoutWidget)
self.formLayout.setContentsMargins(9, 9, 9, 9)
self.formLayout.setObjectName('formLayout')
self.checkBox_2 = QtWidgets.QCheckBox(self.formLayoutWidget)
self.checkBox_2.setObjectName('checkBox_2')
self.formLayout.setWidget(0, QtWidgets.QFormLayout.LabelRole,
self.checkBox_2)
self.progressBar = QtWidgets.QProgressBar(self.formLayoutWidget)
self.progressBar.setProperty('value', 24)
self.progressBar.setObjectName('progressBar')
self.formLayout.setWidget(0, QtWidgets.QFormLayout.FieldRole,
self.progressBar)
self.checkBox_3 = QtWidgets.QCheckBox(self.formLayoutWidget)
self.checkBox_3.setObjectName('checkBox_3')
self.formLayout.setWidget(1, QtWidgets.QFormLayout.LabelRole,
self.checkBox_3)
self.progressBar_2 = \
QtWidgets.QProgressBar(self.formLayoutWidget)
self.progressBar_2.setProperty('value', 24)
self.progressBar_2.setObjectName('progressBar_2')
self.formLayout.setWidget(1, QtWidgets.QFormLayout.FieldRole,
self.progressBar_2)
self.checkBox_4 = QtWidgets.QCheckBox(self.formLayoutWidget)
self.checkBox_4.setObjectName('checkBox_4')
self.formLayout.setWidget(2, QtWidgets.QFormLayout.LabelRole,
self.checkBox_4)
self.progressBar_3 = \
QtWidgets.QProgressBar(self.formLayoutWidget)
self.progressBar_3.setProperty('value', 24)
self.progressBar_3.setObjectName('progressBar_3')
self.formLayout.setWidget(2, QtWidgets.QFormLayout.FieldRole,
self.progressBar_3)
self.checkBox_5 = QtWidgets.QCheckBox(self.formLayoutWidget)
self.checkBox_5.setObjectName('checkBox_5')
self.formLayout.setWidget(3, QtWidgets.QFormLayout.LabelRole,
self.checkBox_5)
self.progressBar_4 = \
QtWidgets.QProgressBar(self.formLayoutWidget)
self.progressBar_4.setProperty('value', 24)
self.progressBar_4.setObjectName('progressBar_4')
self.formLayout.setWidget(3, QtWidgets.QFormLayout.FieldRole,
self.progressBar_4)
count = 6
c = 0
checkBox = []
while count < 10:
checkBox.append(QtWidgets.QCheckBox(self.formLayoutWidget))
checkBox[c].setObjectName('checkBox_' + str(c))
checkBox[c].setText('test_' + str(c))
self.formLayout.setWidget(count,
QtWidgets.QFormLayout.LabelRole, checkBox[c])
self.formLayout.setWidget(count,
QtWidgets.QFormLayout.FieldRole,
QtWidgets.QProgressBar(self.formLayoutWidget))
count = count + 1
c = c + 1
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName('statusbar')
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate('MainWindow', 'MainWindow'
))
self.label.setText(_translate('MainWindow',
'<html><head/><body><p><span style=" font-weight:600; color:#000000;">Search String</span><span style=" font-weight:600; color:#ff0000;">*</span></p></body></html>'
))
self.submit.setText(_translate('MainWindow', 'Search'))
self.groupBox.setTitle(_translate('MainWindow', 'Server List'))
__sortingEnabled = self.serverList.isSortingEnabled()
self.serverList.setSortingEnabled(False)
item = self.serverList.item(0)
item.setText(_translate('MainWindow', 'TVOL'))
item = self.serverList.item(1)
item.setText(_translate('MainWindow', 'QA2'))
item = self.serverList.item(2)
item.setText(_translate('MainWindow', 'CVOL'))
self.serverList.setSortingEnabled(__sortingEnabled)
self.groupBox_2.setTitle(_translate('MainWindow',
'Other Configuration'))
self.autoDownload.setToolTip(_translate('MainWindow',
'<html><head/><body><p><br/></p></body></html>'))
self.autoDownload.setText(_translate('MainWindow',
'Auto Download'))
self.specificFileFlag.setToolTip(_translate('MainWindow',
'<html><head/><body><p>write the file name in "Search String" and Click on Search Button</p></body></html>'
))
self.specificFileFlag.setText(_translate('MainWindow',
'Download Specific file'))
self.downloadSelected.setText(_translate('MainWindow',
'Download Selected'))
self.searchArchive.setText(_translate('MainWindow',
'Search in Archive'))
self.checkBox.setToolTip(_translate('MainWindow',
'<html><head/><body><p>This option will try to compress the file in server before downloading</p></body></html>'
))
self.checkBox.setText(_translate('MainWindow',
'Compress Before Download'))
self.label_2.setText(_translate('MainWindow',
'<html><head/><body><p><span style=" color:#969696;">Created by - Sudipto Khan</span></p></body></html>'
))
self.checkBox_2.setText(_translate('MainWindow', 'CheckBox'))
self.checkBox_3.setText(_translate('MainWindow', 'CheckBox'))
self.checkBox_4.setText(_translate('MainWindow', 'CheckBox'))
self.checkBox_5.setText(_translate('MainWindow', 'CheckBox'))
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_())

How do I pass parameters from the GUI PyQt5 widgets to the python code I have working through a button

This is something I'm doing for work, to speed up a process with the software we use. I'm trying to change a text file by using different regex search & replace functions. I have that working, and I have the GUI the way I want it.
import MainCode
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.setEnabled(True)
MainWindow.resize(786, 73)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(1)
sizePolicy.setVerticalStretch(1)
sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
MainWindow.setSizePolicy(sizePolicy)
MainWindow.setMinimumSize(QtCore.QSize(786, 73))
MainWindow.setWindowOpacity(1.0)
MainWindow.setDockNestingEnabled(True)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.StyleGroupBox = QtWidgets.QGroupBox(self.centralwidget)
self.StyleGroupBox.setGeometry(QtCore.QRect(0, 10, 101, 51))
font = QtGui.QFont()
font.setPointSize(10)
self.StyleGroupBox.setFont(font)
self.StyleGroupBox.setFocusPolicy(QtCore.Qt.NoFocus)
self.StyleGroupBox.setCheckable(True)
self.StyleGroupBox.setChecked(False)
self.StyleGroupBox.setObjectName("StyleGroupBox")
self.StyleComboBox = QtWidgets.QComboBox(self.StyleGroupBox)
self.StyleComboBox.setGeometry(QtCore.QRect(10, 20, 81, 31))
self.StyleComboBox.setMinimumSize(QtCore.QSize(69, 0))
self.StyleComboBox.setSizeIncrement(QtCore.QSize(5, 5))
self.StyleComboBox.setFocusPolicy(QtCore.Qt.ClickFocus)
self.StyleComboBox.setMaxCount(100)
self.StyleComboBox.setSizeAdjustPolicy(QtWidgets.QComboBox.AdjustToContentsOnFirstShow)
self.StyleComboBox.setMinimumContentsLength(1)
self.StyleComboBox.setDuplicatesEnabled(True)
self.StyleComboBox.setObjectName("StyleComboBox")
self.StyleComboBox.addItem("")
self.StyleComboBox.addItem("")
self.StyleComboBox.addItem("")
self.StyleComboBox.addItem("")
self.StyleComboBox.addItem("")
self.FontGroupBox = QtWidgets.QGroupBox(self.centralwidget)
self.FontGroupBox.setEnabled(True)
self.FontGroupBox.setGeometry(QtCore.QRect(100, 10, 81, 51))
font = QtGui.QFont()
font.setPointSize(10)
self.FontGroupBox.setFont(font)
self.FontGroupBox.setFocusPolicy(QtCore.Qt.NoFocus)
self.FontGroupBox.setCheckable(True)
self.FontGroupBox.setChecked(False)
self.FontGroupBox.setObjectName("FontGroupBox")
self.FontSpinBox = QtWidgets.QSpinBox(self.FontGroupBox)
self.FontSpinBox.setGeometry(QtCore.QRect(10, 20, 61, 31))
font = QtGui.QFont()
font.setPointSize(12)
self.FontSpinBox.setFont(font)
self.FontSpinBox.setFocusPolicy(QtCore.Qt.StrongFocus)
self.FontSpinBox.setMinimum(8)
self.FontSpinBox.setMaximum(200)
self.FontSpinBox.setProperty("value", 24)
self.FontSpinBox.setObjectName("FontSpinBox")
self.OpacityGroupBox = QtWidgets.QGroupBox(self.centralwidget)
self.OpacityGroupBox.setEnabled(True)
self.OpacityGroupBox.setGeometry(QtCore.QRect(180, 10, 81, 51))
font = QtGui.QFont()
font.setPointSize(10)
self.OpacityGroupBox.setFont(font)
self.OpacityGroupBox.setFocusPolicy(QtCore.Qt.ClickFocus)
self.OpacityGroupBox.setCheckable(True)
self.OpacityGroupBox.setChecked(False)
self.OpacityGroupBox.setObjectName("OpacityGroupBox")
self.OpacityDoubleSpinBox = QtWidgets.QDoubleSpinBox(self.OpacityGroupBox)
self.OpacityDoubleSpinBox.setGeometry(QtCore.QRect(10, 20, 61, 31))
font = QtGui.QFont()
font.setPointSize(12)
self.OpacityDoubleSpinBox.setFont(font)
self.OpacityDoubleSpinBox.setToolTip("")
self.OpacityDoubleSpinBox.setDecimals(2)
self.OpacityDoubleSpinBox.setMaximum(1.0)
self.OpacityDoubleSpinBox.setSingleStep(0.01)
self.OpacityDoubleSpinBox.setProperty("value", 1.0)
self.OpacityDoubleSpinBox.setObjectName("OpacityDoubleSpinBox")
self.NextPageGroupBox = QtWidgets.QGroupBox(self.centralwidget)
self.NextPageGroupBox.setEnabled(True)
self.NextPageGroupBox.setGeometry(QtCore.QRect(260, 10, 91, 51))
font = QtGui.QFont()
font.setPointSize(10)
self.NextPageGroupBox.setFont(font)
self.NextPageGroupBox.setFocusPolicy(QtCore.Qt.ClickFocus)
self.NextPageGroupBox.setCheckable(True)
self.NextPageGroupBox.setChecked(False)
self.NextPageGroupBox.setObjectName("NextPageGroupBox")
self.NextPageSpinBox = QtWidgets.QSpinBox(self.NextPageGroupBox)
self.NextPageSpinBox.setGeometry(QtCore.QRect(10, 20, 81, 31))
font = QtGui.QFont()
font.setPointSize(12)
self.NextPageSpinBox.setFont(font)
self.NextPageSpinBox.setFocusPolicy(QtCore.Qt.StrongFocus)
self.NextPageSpinBox.setInputMethodHints(QtCore.Qt.ImhDigitsOnly)
self.NextPageSpinBox.setButtonSymbols(QtWidgets.QAbstractSpinBox.PlusMinus)
self.NextPageSpinBox.setAccelerated(True)
self.NextPageSpinBox.setMaximum(999999999)
self.NextPageSpinBox.setDisplayIntegerBase(10)
self.NextPageSpinBox.setObjectName("NextPageSpinBox")
self.ZindexGroupBox = QtWidgets.QGroupBox(self.centralwidget)
self.ZindexGroupBox.setEnabled(True)
self.ZindexGroupBox.setGeometry(QtCore.QRect(350, 10, 71, 51))
font = QtGui.QFont()
font.setPointSize(10)
self.ZindexGroupBox.setFont(font)
self.ZindexGroupBox.setFocusPolicy(QtCore.Qt.ClickFocus)
self.ZindexGroupBox.setCheckable(True)
self.ZindexGroupBox.setChecked(False)
self.ZindexGroupBox.setObjectName("ZindexGroupBox")
self.ZindexSpinBox = QtWidgets.QSpinBox(self.ZindexGroupBox)
self.ZindexSpinBox.setGeometry(QtCore.QRect(10, 20, 51, 31))
font = QtGui.QFont()
font.setPointSize(12)
self.ZindexSpinBox.setFont(font)
self.ZindexSpinBox.setObjectName("ZindexSpinBox")
self.AddChangeFrame = QtWidgets.QFrame(self.centralwidget)
self.AddChangeFrame.setEnabled(True)
self.AddChangeFrame.setGeometry(QtCore.QRect(420, 0, 351, 71))
font = QtGui.QFont()
font.setPointSize(8)
self.AddChangeFrame.setFont(font)
self.AddChangeFrame.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.AddChangeFrame.setFrameShadow(QtWidgets.QFrame.Raised)
self.AddChangeFrame.setObjectName("AddChangeFrame")
self.NewButtonsSpinBox = QtWidgets.QSpinBox(self.AddChangeFrame)
self.NewButtonsSpinBox.setGeometry(QtCore.QRect(10, 20, 41, 31))
font = QtGui.QFont()
font.setPointSize(11)
font.setBold(False)
font.setWeight(50)
self.NewButtonsSpinBox.setFont(font)
self.NewButtonsSpinBox.setMouseTracking(True)
self.NewButtonsSpinBox.setAlignment(QtCore.Qt.AlignCenter)
self.NewButtonsSpinBox.setMinimum(1)
self.NewButtonsSpinBox.setObjectName("NewButtonsSpinBox")
self.NewButtonsRadio = QtWidgets.QRadioButton(self.AddChangeFrame)
self.NewButtonsRadio.setGeometry(QtCore.QRect(0, 0, 161, 21))
font = QtGui.QFont()
font.setPointSize(12)
self.NewButtonsRadio.setFont(font)
self.NewButtonsRadio.setFocusPolicy(QtCore.Qt.ClickFocus)
self.NewButtonsRadio.setObjectName("NewButtonsRadio")
self.StartItemLabel = QtWidgets.QLabel(self.AddChangeFrame)
self.StartItemLabel.setGeometry(QtCore.QRect(70, 20, 61, 21))
self.StartItemLabel.setObjectName("StartItemLabel")
self.EndingItemLabel = QtWidgets.QLabel(self.AddChangeFrame)
self.EndingItemLabel.setGeometry(QtCore.QRect(160, 20, 51, 20))
self.EndingItemLabel.setObjectName("EndingItemLabel")
self.StartItemNumberSpinBox = QtWidgets.QSpinBox(self.AddChangeFrame)
self.StartItemNumberSpinBox.setGeometry(QtCore.QRect(60, 40, 81, 22))
self.StartItemNumberSpinBox.setObjectName("StartItemNumberSpinBox")
self.EndItemNumberSpinBox = QtWidgets.QSpinBox(self.AddChangeFrame)
self.EndItemNumberSpinBox.setGeometry(QtCore.QRect(150, 40, 81, 22))
self.EndItemNumberSpinBox.setObjectName("EndItemNumberSpinBox")
self.ChangeRadioButton = QtWidgets.QRadioButton(self.AddChangeFrame)
self.ChangeRadioButton.setGeometry(QtCore.QRect(170, 0, 181, 21))
font = QtGui.QFont()
font.setPointSize(12)
self.ChangeRadioButton.setFont(font)
self.ChangeRadioButton.setChecked(True)
self.ChangeRadioButton.setObjectName("ChangeRadioButton")
self.SubmitChangesButton = QtWidgets.QPushButton(self.centralwidget)
self.SubmitChangesButton.setGeometry(QtCore.QRect(660, 30, 131, 41))
font = QtGui.QFont()
font.setFamily("Segoe UI")
font.setPointSize(11)
font.setBold(True)
font.setItalic(True)
font.setWeight(75)
font.setKerning(True)
self.SubmitChangesButton.setFont(font)
self.SubmitChangesButton.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.SubmitChangesButton.setAutoFillBackground(True)
self.SubmitChangesButton.setObjectName("SubmitChangesButton")
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Simphony Button Editor"))
self.StyleGroupBox.setToolTip(_translate("MainWindow", "<html><head/><body><p>Changes the style & color of the button using the drop-down menu.</p></body></html>"))
self.StyleGroupBox.setWhatsThis(_translate("MainWindow", "<html><head/><body><p>Changes style & color of button</p></body></html>"))
self.StyleGroupBox.setTitle(_translate("MainWindow", "Color/ Style"))
self.StyleComboBox.setItemText(0, _translate("MainWindow", "Button1"))
self.StyleComboBox.setItemText(1, _translate("MainWindow", "Button2"))
self.StyleComboBox.setItemText(2, _translate("MainWindow", "Button3"))
self.StyleComboBox.setItemText(3, _translate("MainWindow", "Button4"))
self.StyleComboBox.setItemText(4, _translate("MainWindow", "Button5"))
self.FontGroupBox.setToolTip(_translate("MainWindow", "<html><head/><body><p>Changes the font size the button text.</p></body></html>"))
self.FontGroupBox.setTitle(_translate("MainWindow", "Font Size"))
self.OpacityGroupBox.setToolTip(_translate("MainWindow", "<html><head/><body><p>Changes the percentage Opacity (visibility) of the button.</p></body></html>"))
self.OpacityGroupBox.setTitle(_translate("MainWindow", "Opacity"))
self.NextPageGroupBox.setToolTip(_translate("MainWindow", "<html><head/><body><p>Assigns the next menu page to jump to after button completion. </p></body></html>"))
self.NextPageGroupBox.setTitle(_translate("MainWindow", "Next Page"))
self.ZindexGroupBox.setToolTip(_translate("MainWindow", "<html><head/><body><p>Changes the visibility layer of the button. If a button is set to 1 and another set to 2 in the same spot then you would only see the button with Z index 2.</p></body></html>"))
self.ZindexGroupBox.setTitle(_translate("MainWindow", "Z Index"))
self.NewButtonsRadio.setText(_translate("MainWindow", "Create New Buttons"))
self.StartItemLabel.setText(_translate("MainWindow", "Start Item#"))
self.EndingItemLabel.setText(_translate("MainWindow", "End Item#"))
self.StartItemNumberSpinBox.setToolTip(_translate("MainWindow", "<html><head/><body><p>Enter Item number. Items must be in sequintial order if adding multiple buttons.</p></body></html>"))
self.EndItemNumberSpinBox.setToolTip(_translate("MainWindow", "<html><head/><body><p>Items must be in sequintial order if adding multiple buttons.</p></body></html>"))
self.ChangeRadioButton.setText(_translate("MainWindow", "Update Copied Buttons"))
self.SubmitChangesButton.setText(_translate("MainWindow", "Make Changes"))
class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.setupUi(self)
self.SubmitChangesButton.clicked.connect(self.on_clicked)
#QtCore.pyqtSlot()
def on_clicked(self):
if self.FontGroupBox.isChecked() is True:
print('Font Size = ' + self.FontSpinBox.value())
if self.StyleGroupBox.isChecked() is True:
print(self.StyleComboBox.Text())
if self.OpacityGroupBox.isChecked() is True:
print('Opacity% = ' + self.OpacityDoubleSpinBox.value())
if self.NextPageGroupBox.isChecked() is True:
print('Next Page = ' + self.NextPageSpinBox.value())
if self.ZindexGroupBox.isChecked() is True:
print('Z Index = ' + self.ZindexSpinBox.value())
if __name__ == "__main__":
import sys
import MainCode
import MyDesign
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindo`enter code here`w()
ui.setupUi(MainWindow)
MainWindow.show()
print(Ui_MainWindow)
sys.exit(app.exec_())
I just need to be able to pull the results from the input that has been entered, if the frames are enabled(checked) when I click the submit buttons. Output should be true or false for checkboxes and radio buttons and integers, a double, and a string for the rest. I'm sure I'm missing something simple.
We created a class MainWindow for the top-level window.
Create an instance of it and display the widget on the screen.
w = MainWindow()
w.show()
Added the ability to get the selected item in the QComboBox drop-down list.
Corrected the output format in the on_clicked method.
#import MainCode
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.setEnabled(True)
MainWindow.resize(786, 73)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(1)
sizePolicy.setVerticalStretch(1)
sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
MainWindow.setSizePolicy(sizePolicy)
MainWindow.setMinimumSize(QtCore.QSize(786, 73))
MainWindow.setWindowOpacity(1.0)
MainWindow.setDockNestingEnabled(True)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.StyleGroupBox = QtWidgets.QGroupBox(self.centralwidget)
self.StyleGroupBox.setGeometry(QtCore.QRect(0, 10, 101, 51))
font = QtGui.QFont()
font.setPointSize(10)
self.StyleGroupBox.setFont(font)
self.StyleGroupBox.setFocusPolicy(QtCore.Qt.NoFocus)
self.StyleGroupBox.setCheckable(True)
self.StyleGroupBox.setChecked(False)
self.StyleGroupBox.setObjectName("StyleGroupBox")
self.StyleComboBox = QtWidgets.QComboBox(self.StyleGroupBox)
self.StyleComboBox.setGeometry(QtCore.QRect(10, 20, 81, 31))
self.StyleComboBox.setMinimumSize(QtCore.QSize(69, 0))
self.StyleComboBox.setSizeIncrement(QtCore.QSize(5, 5))
self.StyleComboBox.setFocusPolicy(QtCore.Qt.ClickFocus)
self.StyleComboBox.setMaxCount(100)
self.StyleComboBox.setSizeAdjustPolicy(QtWidgets.QComboBox.AdjustToContentsOnFirstShow)
self.StyleComboBox.setMinimumContentsLength(1)
self.StyleComboBox.setDuplicatesEnabled(True)
self.StyleComboBox.setObjectName("StyleComboBox")
self.StyleComboBox.addItem("")
self.StyleComboBox.addItem("")
self.StyleComboBox.addItem("")
self.StyleComboBox.addItem("")
self.StyleComboBox.addItem("")
self.FontGroupBox = QtWidgets.QGroupBox(self.centralwidget)
self.FontGroupBox.setEnabled(True)
self.FontGroupBox.setGeometry(QtCore.QRect(100, 10, 81, 51))
font = QtGui.QFont()
font.setPointSize(10)
self.FontGroupBox.setFont(font)
self.FontGroupBox.setFocusPolicy(QtCore.Qt.NoFocus)
self.FontGroupBox.setCheckable(True)
self.FontGroupBox.setChecked(False)
self.FontGroupBox.setObjectName("FontGroupBox")
self.FontSpinBox = QtWidgets.QSpinBox(self.FontGroupBox)
self.FontSpinBox.setGeometry(QtCore.QRect(10, 20, 61, 31))
font = QtGui.QFont()
font.setPointSize(12)
self.FontSpinBox.setFont(font)
self.FontSpinBox.setFocusPolicy(QtCore.Qt.StrongFocus)
self.FontSpinBox.setMinimum(8)
self.FontSpinBox.setMaximum(200)
self.FontSpinBox.setProperty("value", 24)
self.FontSpinBox.setObjectName("FontSpinBox")
self.OpacityGroupBox = QtWidgets.QGroupBox(self.centralwidget)
self.OpacityGroupBox.setEnabled(True)
self.OpacityGroupBox.setGeometry(QtCore.QRect(180, 10, 81, 51))
font = QtGui.QFont()
font.setPointSize(10)
self.OpacityGroupBox.setFont(font)
self.OpacityGroupBox.setFocusPolicy(QtCore.Qt.ClickFocus)
self.OpacityGroupBox.setCheckable(True)
self.OpacityGroupBox.setChecked(False)
self.OpacityGroupBox.setObjectName("OpacityGroupBox")
self.OpacityDoubleSpinBox = QtWidgets.QDoubleSpinBox(self.OpacityGroupBox)
self.OpacityDoubleSpinBox.setGeometry(QtCore.QRect(10, 20, 61, 31))
font = QtGui.QFont()
font.setPointSize(12)
self.OpacityDoubleSpinBox.setFont(font)
self.OpacityDoubleSpinBox.setToolTip("")
self.OpacityDoubleSpinBox.setDecimals(2)
self.OpacityDoubleSpinBox.setMaximum(1.0)
self.OpacityDoubleSpinBox.setSingleStep(0.01)
self.OpacityDoubleSpinBox.setProperty("value", 1.0)
self.OpacityDoubleSpinBox.setObjectName("OpacityDoubleSpinBox")
self.NextPageGroupBox = QtWidgets.QGroupBox(self.centralwidget)
self.NextPageGroupBox.setEnabled(True)
self.NextPageGroupBox.setGeometry(QtCore.QRect(260, 10, 91, 51))
font = QtGui.QFont()
font.setPointSize(10)
self.NextPageGroupBox.setFont(font)
self.NextPageGroupBox.setFocusPolicy(QtCore.Qt.ClickFocus)
self.NextPageGroupBox.setCheckable(True)
self.NextPageGroupBox.setChecked(False)
self.NextPageGroupBox.setObjectName("NextPageGroupBox")
self.NextPageSpinBox = QtWidgets.QSpinBox(self.NextPageGroupBox)
self.NextPageSpinBox.setGeometry(QtCore.QRect(10, 20, 81, 31))
font = QtGui.QFont()
font.setPointSize(12)
self.NextPageSpinBox.setFont(font)
self.NextPageSpinBox.setFocusPolicy(QtCore.Qt.StrongFocus)
self.NextPageSpinBox.setInputMethodHints(QtCore.Qt.ImhDigitsOnly)
self.NextPageSpinBox.setButtonSymbols(QtWidgets.QAbstractSpinBox.PlusMinus)
self.NextPageSpinBox.setAccelerated(True)
self.NextPageSpinBox.setMaximum(999999999)
self.NextPageSpinBox.setDisplayIntegerBase(10)
self.NextPageSpinBox.setObjectName("NextPageSpinBox")
self.ZindexGroupBox = QtWidgets.QGroupBox(self.centralwidget)
self.ZindexGroupBox.setEnabled(True)
self.ZindexGroupBox.setGeometry(QtCore.QRect(350, 10, 71, 51))
font = QtGui.QFont()
font.setPointSize(10)
self.ZindexGroupBox.setFont(font)
self.ZindexGroupBox.setFocusPolicy(QtCore.Qt.ClickFocus)
self.ZindexGroupBox.setCheckable(True)
self.ZindexGroupBox.setChecked(False)
self.ZindexGroupBox.setObjectName("ZindexGroupBox")
self.ZindexSpinBox = QtWidgets.QSpinBox(self.ZindexGroupBox)
self.ZindexSpinBox.setGeometry(QtCore.QRect(10, 20, 51, 31))
font = QtGui.QFont()
font.setPointSize(12)
self.ZindexSpinBox.setFont(font)
self.ZindexSpinBox.setObjectName("ZindexSpinBox")
self.AddChangeFrame = QtWidgets.QFrame(self.centralwidget)
self.AddChangeFrame.setEnabled(True)
self.AddChangeFrame.setGeometry(QtCore.QRect(420, 0, 351, 71))
font = QtGui.QFont()
font.setPointSize(8)
self.AddChangeFrame.setFont(font)
self.AddChangeFrame.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.AddChangeFrame.setFrameShadow(QtWidgets.QFrame.Raised)
self.AddChangeFrame.setObjectName("AddChangeFrame")
self.NewButtonsSpinBox = QtWidgets.QSpinBox(self.AddChangeFrame)
self.NewButtonsSpinBox.setGeometry(QtCore.QRect(10, 20, 41, 31))
font = QtGui.QFont()
font.setPointSize(11)
font.setBold(False)
font.setWeight(50)
self.NewButtonsSpinBox.setFont(font)
self.NewButtonsSpinBox.setMouseTracking(True)
self.NewButtonsSpinBox.setAlignment(QtCore.Qt.AlignCenter)
self.NewButtonsSpinBox.setMinimum(1)
self.NewButtonsSpinBox.setObjectName("NewButtonsSpinBox")
self.NewButtonsRadio = QtWidgets.QRadioButton(self.AddChangeFrame)
self.NewButtonsRadio.setGeometry(QtCore.QRect(0, 0, 161, 21))
font = QtGui.QFont()
font.setPointSize(12)
self.NewButtonsRadio.setFont(font)
self.NewButtonsRadio.setFocusPolicy(QtCore.Qt.ClickFocus)
self.NewButtonsRadio.setObjectName("NewButtonsRadio")
self.StartItemLabel = QtWidgets.QLabel(self.AddChangeFrame)
self.StartItemLabel.setGeometry(QtCore.QRect(70, 20, 61, 21))
self.StartItemLabel.setObjectName("StartItemLabel")
self.EndingItemLabel = QtWidgets.QLabel(self.AddChangeFrame)
self.EndingItemLabel.setGeometry(QtCore.QRect(160, 20, 51, 20))
self.EndingItemLabel.setObjectName("EndingItemLabel")
self.StartItemNumberSpinBox = QtWidgets.QSpinBox(self.AddChangeFrame)
self.StartItemNumberSpinBox.setGeometry(QtCore.QRect(60, 40, 81, 22))
self.StartItemNumberSpinBox.setObjectName("StartItemNumberSpinBox")
self.EndItemNumberSpinBox = QtWidgets.QSpinBox(self.AddChangeFrame)
self.EndItemNumberSpinBox.setGeometry(QtCore.QRect(150, 40, 81, 22))
self.EndItemNumberSpinBox.setObjectName("EndItemNumberSpinBox")
self.ChangeRadioButton = QtWidgets.QRadioButton(self.AddChangeFrame)
self.ChangeRadioButton.setGeometry(QtCore.QRect(170, 0, 181, 21))
font = QtGui.QFont()
font.setPointSize(12)
self.ChangeRadioButton.setFont(font)
self.ChangeRadioButton.setChecked(True)
self.ChangeRadioButton.setObjectName("ChangeRadioButton")
self.SubmitChangesButton = QtWidgets.QPushButton(self.centralwidget)
self.SubmitChangesButton.setGeometry(QtCore.QRect(660, 30, 131, 41))
font = QtGui.QFont()
font.setFamily("Segoe UI")
font.setPointSize(11)
font.setBold(True)
font.setItalic(True)
font.setWeight(75)
font.setKerning(True)
self.SubmitChangesButton.setFont(font)
self.SubmitChangesButton.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.SubmitChangesButton.setAutoFillBackground(True)
self.SubmitChangesButton.setObjectName("SubmitChangesButton")
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Simphony Button Editor"))
self.StyleGroupBox.setToolTip(_translate("MainWindow", "<html><head/><body><p>Changes the style & color of the button using the drop-down menu.</p></body></html>"))
self.StyleGroupBox.setWhatsThis(_translate("MainWindow", "<html><head/><body><p>Changes style & color of button</p></body></html>"))
self.StyleGroupBox.setTitle(_translate("MainWindow", "Color/ Style"))
self.StyleComboBox.setItemText(0, _translate("MainWindow", "Button1"))
self.StyleComboBox.setItemText(1, _translate("MainWindow", "Button2"))
self.StyleComboBox.setItemText(2, _translate("MainWindow", "Button3"))
self.StyleComboBox.setItemText(3, _translate("MainWindow", "Button4"))
self.StyleComboBox.setItemText(4, _translate("MainWindow", "Button5"))
self.FontGroupBox.setToolTip(_translate("MainWindow", "<html><head/><body><p>Changes the font size the button text.</p></body></html>"))
self.FontGroupBox.setTitle(_translate("MainWindow", "Font Size"))
self.OpacityGroupBox.setToolTip(_translate("MainWindow", "<html><head/><body><p>Changes the percentage Opacity (visibility) of the button.</p></body></html>"))
self.OpacityGroupBox.setTitle(_translate("MainWindow", "Opacity"))
self.NextPageGroupBox.setToolTip(_translate("MainWindow", "<html><head/><body><p>Assigns the next menu page to jump to after button completion. </p></body></html>"))
self.NextPageGroupBox.setTitle(_translate("MainWindow", "Next Page"))
self.ZindexGroupBox.setToolTip(_translate("MainWindow", "<html><head/><body><p>Changes the visibility layer of the button. If a button is set to 1 and another set to 2 in the same spot then you would only see the button with Z index 2.</p></body></html>"))
self.ZindexGroupBox.setTitle(_translate("MainWindow", "Z Index"))
self.NewButtonsRadio.setText(_translate("MainWindow", "Create New Buttons"))
self.StartItemLabel.setText(_translate("MainWindow", "Start Item#"))
self.EndingItemLabel.setText(_translate("MainWindow", "End Item#"))
self.StartItemNumberSpinBox.setToolTip(_translate("MainWindow", "<html><head/><body><p>Enter Item number. Items must be in sequintial order if adding multiple buttons.</p></body></html>"))
self.EndItemNumberSpinBox.setToolTip(_translate("MainWindow", "<html><head/><body><p>Items must be in sequintial order if adding multiple buttons.</p></body></html>"))
self.ChangeRadioButton.setText(_translate("MainWindow", "Update Copied Buttons"))
self.SubmitChangesButton.setText(_translate("MainWindow", "Make Changes"))
class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.setupUi(self)
self.SubmitChangesButton.clicked.connect(self.on_clicked)
# + vvvv
self.itemTextComboBox = "Button1"
self.StyleComboBox.activated[str].connect(self.activatedItemComboBox)
def activatedItemComboBox(self, text):
self.itemTextComboBox = text
# + ^^^^
#QtCore.pyqtSlot()
def on_clicked(self):
if self.StyleGroupBox.isChecked() is True:
print(self.itemTextComboBox)
if self.FontGroupBox.isChecked() is True:
print('Font Size = {}'.format(self.FontSpinBox.value()))
if self.OpacityGroupBox.isChecked() is True:
print('Opacity% = {:.2f}'.format(self.OpacityDoubleSpinBox.value()))
if self.NextPageGroupBox.isChecked() is True:
print('Next Page = {}'.format(self.NextPageSpinBox.value()))
if self.ZindexGroupBox.isChecked() is True:
print('Z Index = {}'.format(self.ZindexSpinBox.value()))
if __name__ == "__main__":
import sys
# import MainCode
# import MyDesign
app = QtWidgets.QApplication(sys.argv)
# MainWindow = QtWidgets.QMainWindow()
# ui = Ui_MainWindow()
# ui.setupUi(MainWindow)
# MainWindow.show()
# print(Ui_MainWindow)
w = MainWindow() # <---
w.show() # <---
sys.exit(app.exec_())

Created ui in Qt designer does not look the same when python code is run

I created a ui in Qt designer and transitioned the .ui file into .py file. However, when I run the python code, The ui does not look the same as in the designer when I run the code. I don't understand why this is happening as I can see all of the elements in the code?
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_FirstWindow(object):
def setupUi(self, FirstWindow):
FirstWindow.setObjectName("FirstWindow")
FirstWindow.resize(400, 300)
self.centralWidget = QtWidgets.QWidget(FirstWindow)
self.centralWidget.setObjectName("centralWidget")
self.welcomelabel = QtWidgets.QLabel(self.centralWidget)
self.welcomelabel.setGeometry(QtCore.QRect(90, 10, 211, 20))
font = QtGui.QFont()
font.setBold(True)
font.setWeight(75)
self.welcomelabel.setFont(font)
self.welcomelabel.setAlignment(QtCore.Qt.AlignCenter)
self.welcomelabel.setObjectName("welcomelabel")
self.pushButton = QtWidgets.QPushButton(self.centralWidget)
self.pushButton.setGeometry(QtCore.QRect(150, 120, 80, 16))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(self.centralWidget)
self.pushButton_2.setGeometry(QtCore.QRect(290, 120, 80, 16))
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_3 = QtWidgets.QPushButton(self.centralWidget)
self.pushButton_3.setGeometry(QtCore.QRect(10, 120, 80, 16))
self.pushButton_3.setObjectName("pushButton_3")
self.layoutWidget = QtWidgets.QWidget(self.centralWidget)
self.layoutWidget.setGeometry(QtCore.QRect(50, 50, 168, 54))
self.layoutWidget.setObjectName("layoutWidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.layoutWidget)
self.verticalLayout.setContentsMargins(11, 11, 11, 11)
self.verticalLayout.setSpacing(6)
self.verticalLayout.setObjectName("verticalLayout")
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setContentsMargins(11, 11, 11, 11)
self.horizontalLayout.setSpacing(16)
self.horizontalLayout.setObjectName("horizontalLayout")
self.rowcountlabel = QtWidgets.QLabel(self.layoutWidget)
self.rowcountlabel.setObjectName("rowcountlabel")
self.horizontalLayout.addWidget(self.rowcountlabel)
self.rowcounentry = QtWidgets.QLineEdit(self.layoutWidget)
self.rowcounentry.setObjectName("rowcounentry")
self.horizontalLayout.addWidget(self.rowcounentry)
self.verticalLayout.addLayout(self.horizontalLayout)
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setContentsMargins(11, 11, 11, 11)
self.horizontalLayout_2.setSpacing(6)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.columncountlabel = QtWidgets.QLabel(self.layoutWidget)
self.columncountlabel.setObjectName("columncountlabel")
self.horizontalLayout_2.addWidget(self.columncountlabel)
self.ColumnNOentry = QtWidgets.QLineEdit(self.layoutWidget)
self.ColumnNOentry.setObjectName("ColumnNOentry")
self.horizontalLayout_2.addWidget(self.ColumnNOentry)
self.verticalLayout.addLayout(self.horizontalLayout_2)
FirstWindow.setCentralWidget(self.centralWidget)
self.menuBar = QtWidgets.QMenuBar(FirstWindow)
self.menuBar.setGeometry(QtCore.QRect(0, 0, 400, 17))
self.menuBar.setObjectName("menuBar")
FirstWindow.setMenuBar(self.menuBar)
self.mainToolBar = QtWidgets.QToolBar(FirstWindow)
self.mainToolBar.setObjectName("mainToolBar")
FirstWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.mainToolBar)
self.statusBar = QtWidgets.QStatusBar(FirstWindow)
self.statusBar.setObjectName("statusBar")
FirstWindow.setStatusBar(self.statusBar)
self.retranslateUi(FirstWindow)
QtCore.QMetaObject.connectSlotsByName(FirstWindow)
def retranslateUi(self, FirstWindow):
_translate = QtCore.QCoreApplication.translate
FirstWindow.setWindowTitle(_translate("FirstWindow", "FirstWindow"))
self.welcomelabel.setText(_translate("FirstWindow", "<html><head/><body><p><span style=\" font-size:12pt;\">Welcome to the Data Generator</span></p></body></html>"))
self.pushButton.setText(_translate("FirstWindow", "Continue"))
self.pushButton_2.setText(_translate("FirstWindow", "Exit"))
self.pushButton_3.setText(_translate("FirstWindow", "Instructions"))
self.rowcountlabel.setText(_translate("FirstWindow", "<html><head/><body><p><span style=\" font-weight:600;\">How Many Rows? </span></p></body></html>"))
self.columncountlabel.setText(_translate("FirstWindow", "<html><head/><body><p><span style=\" font-weight:600;\">How Many Columns? </span></p></body></html>"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
FirstWindow = QtWidgets.QMainWindow()
ui = Ui_FirstWindow()
ui.setupUi(FirstWindow)
FirstWindow.show()
sys.exit(app.exec_())
I expect this:
but it looks like this:
For some reason you do not put all the widgets in the central widget?
I unfortunately could not see what result you want to get.
Try it:
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_FirstWindow(object):
def setupUi(self, FirstWindow):
FirstWindow.setObjectName("FirstWindow")
FirstWindow.resize(400, 300)
self.centralWidget = QtWidgets.QWidget(FirstWindow)
self.centralWidget.setObjectName("centralWidget")
self.welcomelabel = QtWidgets.QLabel(self.centralWidget)
self.welcomelabel.setGeometry(QtCore.QRect(90, 10, 211, 20))
font = QtGui.QFont()
font.setBold(True)
font.setWeight(75)
self.welcomelabel.setFont(font)
self.welcomelabel.setAlignment(QtCore.Qt.AlignCenter)
self.welcomelabel.setObjectName("welcomelabel")
self.pushButton = QtWidgets.QPushButton(self.centralWidget)
self.pushButton.setGeometry(QtCore.QRect(150, 120, 80, 16))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(self.centralWidget)
self.pushButton_2.setGeometry(QtCore.QRect(290, 120, 80, 16))
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_3 = QtWidgets.QPushButton(self.centralWidget)
self.pushButton_3.setGeometry(QtCore.QRect(10, 120, 80, 16))
self.pushButton_3.setObjectName("pushButton_3")
# +++ vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
self.hLayout = QtWidgets.QHBoxLayout()
self.hLayout.setContentsMargins(11, 11, 11, 11)
self.hLayout.setSpacing(6)
self.hLayout.setObjectName("hLayout")
self.hLayout.addWidget(self.pushButton_3)
self.hLayout.addWidget(self.pushButton)
self.hLayout.addWidget(self.pushButton_2)
# +++ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
self.layoutWidget = QtWidgets.QWidget(self.centralWidget)
self.layoutWidget.setGeometry(QtCore.QRect(50, 50, 168, 54))
self.layoutWidget.setObjectName("layoutWidget")
# self.verticalLayout = QtWidgets.QVBoxLayout(self.layoutWidget)
self.verticalLayout = QtWidgets.QVBoxLayout(self.centralWidget) # +++
self.verticalLayout.setContentsMargins(11, 11, 11, 11)
self.verticalLayout.setSpacing(6)
self.verticalLayout.setObjectName("verticalLayout")
self.verticalLayout.addWidget(self.welcomelabel) # +++
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setContentsMargins(11, 11, 11, 11)
self.horizontalLayout.setSpacing(16)
self.horizontalLayout.setObjectName("horizontalLayout")
self.rowcountlabel = QtWidgets.QLabel(self.layoutWidget)
self.rowcountlabel.setObjectName("rowcountlabel")
self.horizontalLayout.addWidget(self.rowcountlabel)
self.rowcounentry = QtWidgets.QLineEdit(self.layoutWidget)
self.rowcounentry.setObjectName("rowcounentry")
self.horizontalLayout.addWidget(self.rowcounentry)
self.verticalLayout.addLayout(self.horizontalLayout)
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setContentsMargins(11, 11, 11, 11)
self.horizontalLayout_2.setSpacing(6)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.columncountlabel = QtWidgets.QLabel(self.layoutWidget)
self.columncountlabel.setObjectName("columncountlabel")
self.horizontalLayout_2.addWidget(self.columncountlabel)
self.ColumnNOentry = QtWidgets.QLineEdit(self.layoutWidget)
self.ColumnNOentry.setObjectName("ColumnNOentry")
self.horizontalLayout_2.addWidget(self.ColumnNOentry)
self.verticalLayout.addLayout(self.horizontalLayout_2)
self.verticalLayout.addLayout(self.hLayout) # +++
FirstWindow.setCentralWidget(self.centralWidget)
self.menuBar = QtWidgets.QMenuBar(FirstWindow)
self.menuBar.setGeometry(QtCore.QRect(0, 0, 400, 17))
self.menuBar.setObjectName("menuBar")
FirstWindow.setMenuBar(self.menuBar)
self.mainToolBar = QtWidgets.QToolBar(FirstWindow)
self.mainToolBar.setObjectName("mainToolBar")
FirstWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.mainToolBar)
self.statusBar = QtWidgets.QStatusBar(FirstWindow)
self.statusBar.setObjectName("statusBar")
FirstWindow.setStatusBar(self.statusBar)
self.retranslateUi(FirstWindow)
QtCore.QMetaObject.connectSlotsByName(FirstWindow)
def retranslateUi(self, FirstWindow):
_translate = QtCore.QCoreApplication.translate
FirstWindow.setWindowTitle(_translate("FirstWindow", "FirstWindow"))
self.welcomelabel.setText(_translate("FirstWindow", "<html><head/><body><p><span style=\" font-size:12pt;\">Welcome to the Data Generator</span></p></body></html>"))
self.pushButton.setText(_translate("FirstWindow", "Continue"))
self.pushButton_2.setText(_translate("FirstWindow", "Exit"))
self.pushButton_3.setText(_translate("FirstWindow", "Instructions"))
self.rowcountlabel.setText(_translate("FirstWindow", "<html><head/><body><p><span style=\" font-weight:600;\">How Many Rows ? </span></p></body></html>"))
self.columncountlabel.setText(_translate("FirstWindow", "<html><head/><body><p><span style=\" font-weight:600;\">How Many Columns? </span></p></body></html>"))
class Main(QtWidgets.QMainWindow, Ui_FirstWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
spinbox = Main()
spinbox.show()
sys.exit(app.exec_())

Categories