How to switch window to another class in pyqt5 - python

I have two classes made with pyqt like this:
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(409, 119)
self.label_2 = QtWidgets.QLabel(Dialog)
self.label_2.setGeometry(QtCore.QRect(20, 50, 61, 20))
self.label_2.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.label_2.setObjectName("label_2")
self.lineEdit = QtWidgets.QLineEdit(Dialog)
self.lineEdit.setGeometry(QtCore.QRect(90, 20, 221, 20))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit_2 = QtWidgets.QLineEdit(Dialog)
self.lineEdit_2.setGeometry(QtCore.QRect(90, 50, 221, 20))
self.lineEdit_2.setObjectName("lineEdit_2")
self.pushButton = QtWidgets.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(320, 20, 75, 81))
self.pushButton.setObjectName("pushButton")
self.label_3 = QtWidgets.QLabel(Dialog)
self.label_3.setGeometry(QtCore.QRect(20, 20, 61, 20))
self.label_3.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.label_3.setObjectName("label_3")
self.label_4 = QtWidgets.QLabel(Dialog)
self.label_4.setGeometry(QtCore.QRect(20, 80, 61, 20))
self.label_4.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.label_4.setObjectName("label_4")
self.lineEdit_3 = QtWidgets.QLineEdit(Dialog)
self.lineEdit_3.setGeometry(QtCore.QRect(90, 80, 221, 20))
self.lineEdit_3.setObjectName("lineEdit_3")
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.label_2.setText(_translate("Dialog", "Password"))
self.pushButton.setText(_translate("Dialog", "login"))
self.label_3.setText(_translate("Dialog", "Email"))
self.label_4.setText(_translate("Dialog", "distinct num"))
class Ui_Dialog2(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(485, 429)
self.textBrowser = QtWidgets.QTextBrowser(Dialog)
self.textBrowser.setGeometry(QtCore.QRect(10, 30, 461, 281))
self.textBrowser.setObjectName("textBrowser")
self.label = QtWidgets.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(10, 10, 121, 16))
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(Dialog)
self.label_2.setGeometry(QtCore.QRect(20, 330, 211, 16))
self.label_2.setObjectName("label_2")
self.lineEdit = QtWidgets.QLineEdit(Dialog)
self.lineEdit.setGeometry(QtCore.QRect(10, 350, 391, 20))
self.lineEdit.setObjectName("lineEdit")
self.pushButton = QtWidgets.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(410, 350, 61, 23))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(Dialog)
self.pushButton_2.setGeometry(QtCore.QRect(10, 390, 461, 23))
self.pushButton_2.setObjectName("pushButton_2")
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.label.setText(_translate("Dialog", "process"))
self.label_2.setText(_translate("Dialog", "file"))
self.pushButton.setText(_translate("Dialog", "select"))
self.pushButton_2.setText(_translate("Dialog", "push"))
These two classes have different window sizes and many different things.
How can I switch between two windows based on the login button of Ui_Dialog?
I know how to trigger on the login button but I don't know how to switch to another class.
I want to move to individual dialogs rather than being done in one dialog.

Related

I want to add a Viewbox to my code to make an AutoPan for X axis (pyqtgraph)

This is a GUI where I plot data from serial communication.
I want to add an AutoPan for my GUI but I don't know how.
I read there is an autopan in Viewbox but don't know how to implement it.
The option of Autopan is available when I launch the gui buy right clicking on the gui and selectign it manually but I want it to be enabled by default .
from PyQt5 import QtCore, QtGui, QtWidgets
import pyqtgraph as pg
from random import randint
import serial
ser = serial.Serial('COM5',115200)
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(769, 509)
MainWindow.setStyleSheet("\n""background-color: rgb(212, 212, 212);")
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.graphicsView = PlotWidget(self.centralwidget)
self.graphicsView.setGeometry(QtCore.QRect(80, 110, 561, 271))
self.graphicsView.setObjectName("graphicsView")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(260, 30, 211, 31))
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(20, 10, 151, 80))
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(650, 110, 61, 21))
self.label_3.setObjectName("label_3")
self.label_4 = QtWidgets.QLabel(self.centralwidget)
self.label_4.setGeometry(QtCore.QRect(650, 210, 121, 21))
self.label_4.setObjectName("label_4")
self.comboBox = QtWidgets.QComboBox(self.centralwidget)
self.comboBox.setGeometry(QtCore.QRect(650, 140, 69, 22))
self.comboBox.setStyleSheet("background-color: rgb(255, 255, 255);")
self.comboBox.setEditable(False)
self.comboBox.setObjectName("comboBox")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox_2 = QtWidgets.QComboBox(self.centralwidget)
self.comboBox_2.setGeometry(QtCore.QRect(650, 250, 69, 22))
self.comboBox_2.setStyleSheet("background-color: rgb(255, 255, 255);")
self.comboBox_2.setEditable(False)
self.comboBox_2.setObjectName("comboBox_2")
self.comboBox_2.addItem("")
self.comboBox_2.addItem("")
self.comboBox_2.addItem("")
self.splitter = QtWidgets.QSplitter(self.centralwidget)
self.splitter.setGeometry(QtCore.QRect(80, 410, 561, 51))
self.splitter.setOrientation(QtCore.Qt.Horizontal)
self.splitter.setObjectName("splitter")
self.pushButton = QtWidgets.QPushButton(self.splitter)
font = QtGui.QFont()
font.setBold(True)
font.setWeight(75)
self.pushButton.setFont(font)
self.pushButton.setStyleSheet("background-color: rgb(255, 255, 210);")
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(self.splitter)
font = QtGui.QFont()
font.setBold(True)
font.setWeight(75)
self.pushButton_2.setFont(font)
self.pushButton_2.setStyleSheet("background-color: rgb(255, 255, 210);")
self.pushButton_2.setObjectName("pushButton_2")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 769, 21))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.graphicsView.setBackground('w')
self.retranslateUi(MainWindow)
self.comboBox.setCurrentIndex(1)
self.comboBox_2.setCurrentIndex(2)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Queen Monitor"))
self.label.setText(_translate("MainWindow", "<html><head/><body><p><span style=\" font-size:18pt; font-weight:600;\">QUEEN MONITOR</span></p></body></html>"))
self.label_2.setText(_translate("MainWindow", "<html><head/><body><p><img src=\":/rf/queen.png\"/></p></body></html>"))
self.label_3.setText(_translate("MainWindow", "<html><head/><body><p><span style=\" font-weight:600;\">Baud Rate</span></p></body></html>"))
self.label_4.setText(_translate("MainWindow", "<html><head/><body><p><span style=\" font-weight:600;\">Sampling Frequency</span></p></body></html>"))
self.comboBox.setItemText(0, _translate("MainWindow", "4800"))
self.comboBox.setItemText(1, _translate("MainWindow", "115200"))
self.comboBox_2.setItemText(0, _translate("MainWindow", ".... Hz"))
self.comboBox_2.setItemText(1, _translate("MainWindow", ".... Hz"))
self.comboBox_2.setItemText(2, _translate("MainWindow", ".... Hz"))
self.pushButton.setText(_translate("MainWindow", "START"))
self.pushButton_2.setText(_translate("MainWindow", "CLEAR"))
self.pushButton.clicked.connect(lambda:self.start())
self.pushButton_2.clicked.connect(lambda:self.clear())
self.x = [0]*2 # 100 time points
self.y = [0]*2
pen = pg.mkPen(color=(0, 0, 255))
self.data_line = self.graphicsView.plot(self.x, self.y, pen=pen)
def start(self):
self.timer = QtCore.QTimer()
self.timer.setInterval(1)
self.timer.timeout.connect(self.draw)
self.timer.start()
def draw(self):
"""#self.x = self.x[1:] # Remove the first y element.
self.x.append(self.x[-1] + 1) # Add a new value 1 higher than the last.
#self.y = self.y[1:] # Remove the first
self.y.append( randint(0,200)) # Add a new random value.
self.data_line.setData(self.x, self.y) # Update the data."""
rawData = ser.readline().decode("ascii")
dataSplitted = rawData.split(",")
dataSplitted.pop()
dataSplitted.pop(0)
for self.data_raw in dataSplitted:
self.x.append(self.x[-1] + 1)
self.y.append(int(self.data_raw))
self.data_line.setData(self.x, self.y)
def clear(self):
self.graphicsView.clear()
from pyqtgraph import PlotWidget
import rf_rc
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_())

Automatize code in QTDesigner for objects

I would like to take names and values from 2 list to my QTDesigner text labels and QLineEdit, this is the code which I get:
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(1249, 740)
self.label = QtWidgets.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(370, 180, 68, 19))
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(Dialog)
self.label_2.setGeometry(QtCore.QRect(370, 230, 68, 19))
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(Dialog)
self.label_3.setGeometry(QtCore.QRect(370, 280, 68, 19))
self.label_3.setObjectName("label_3")
self.lineEdit = QtWidgets.QLineEdit(Dialog)
self.lineEdit.setGeometry(QtCore.QRect(450, 180, 113, 25))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit_2 = QtWidgets.QLineEdit(Dialog)
self.lineEdit_2.setGeometry(QtCore.QRect(450, 230, 113, 25))
self.lineEdit_2.setObjectName("lineEdit_2")
self.lineEdit_3 = QtWidgets.QLineEdit(Dialog)
self.lineEdit_3.setGeometry(QtCore.QRect(450, 280, 113, 25))
self.lineEdit_3.setObjectName("lineEdit_3")
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.label.setText(_translate("Dialog", "a"))
self.label_2.setText(_translate("Dialog", "b"))
self.label_3.setText(_translate("Dialog", "c"))
self.lineEdit.setText(_translate("Dialog", "1"))
self.lineEdit_2.setText(_translate("Dialog", "2"))
self.lineEdit_3.setText(_translate("Dialog", "3"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())
And when I have two list of names and I would like to generate automatically those fields, eg.
from PyQt5 import QtCore, QtGui, QtWidgets
list_names = ['a', 'b', 'c']
list_val = [1, 2, 3]
place = [350,400,450]
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(1249, 740)
for i in range(0,len(list_names)):
self.list_names[i] = QtWidgets.QLabel(Dialog)
self.list_names[i].setGeometry(QtCore.QRect(place[i], 110, 68, 19))
self.list_names[i].setObjectName(list_names[i])
self.list_val[i] = QtWidgets.QLineEdit(Dialog)
self.list_val[i].setGeometry(QtCore.QRect(place[i], 110, 113, 25))
self.list_val[i].setObjectName(list_val[i])
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
for i in range(0, len(list_names)):
self.list_names[i].setText(_translate("Dialog", str(list_names[i])))
self.list_val[i].setText(_translate("Dialog", str(list_val[i])))
...
This is an example for only 3 factors in list, I have around 20 of them and I wondering if I can do it in a loop to create the output like that:

Code defined in func not working but runs in main setupui func (pyqt5)

I am making a YouTube downloader for which I created a function which will run when user press download button but this works when the code is in the setupUi function (main function created by pyqt5). The problem is that it does not work when defined inside another function. I do not know why this is happening. The following is the code which I want to run.
def group(self):
if i == 0:
self.groupBox = QtWidgets.QGroupBox(self.scroll)
self.groupBox.setGeometry(QtCore.QRect(70, 20, 431, 91))
self.groupBox.setTitle("")
self.groupBox.setObjectName("groupBox")
self.label = QtWidgets.QLabel(self.groupBox)
self.label.setGeometry(QtCore.QRect(30, 10, 371, 21))
self.label.setObjectName("label")
self.label.setText("b")
self.progressBar = QtWidgets.QProgressBar(self.groupBox)
self.progressBar.setGeometry(QtCore.QRect(40, 50, 221, 20))
self.progressBar.setProperty("value", 24)
self.progressBar.setObjectName("progressBar")
The following the code of main setupUi function
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(662, 423)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.b1 = QtWidgets.QPushButton(self.centralwidget)
self.b1.setGeometry(QtCore.QRect(70, 20, 81, 31))
self.b1.clicked.connect(self.func)
self.b1.setPalette(palette)
font = QtGui.QFont()
font.setBold(True)
font.setWeight(75)
self.b1.setFont(font)
self.b1.setStyleSheet("background-color: rgb(0, 255, 0);")
self.b1.setObjectName("b1")
self.subwin = QtWidgets.QScrollArea(self.centralwidget)
self.subwin.setGeometry(QtCore.QRect(70, 70, 531, 251))
self.subwin.setStyleSheet("background-image:")
self.subwin.setWidgetResizable(True)
self.subwin.setObjectName("subwin")
self.scroll = QtWidgets.QWidget()
self.scroll.setGeometry(QtCore.QRect(0, 0, 529, 249))
self.scroll.setObjectName("scrollAreaWidgetContents")
self.subwin.setWidget(self.scroll)
self.input = QtWidgets.QLineEdit(self.centralwidget)
self.input.setGeometry(QtCore.QRect(250, 20, 351, 31))
self.input.setObjectName("input")
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
I hope this code will be enough and relevant.

Python YouTube downloader with pytube crashes when I search for video

I am making a YouTube video downloader with Python. I made the design with PyQt and edited the code in IDLE. Here is the code.
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'YTD.ui'
#
# Created by: PyQt5 UI code generator 5.15.2
#
# 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
from pytube import YouTube
class Ui_MainWindow(object):
link = ''
video = None
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(354, 210)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.plainTextEdit = QtWidgets.QPlainTextEdit(self.centralwidget)
self.plainTextEdit.setGeometry(QtCore.QRect(10, 10, 261, 31))
self.plainTextEdit.setStyleSheet("font: 12pt \"MS Shell Dlg 2\";")
self.plainTextEdit.setPlainText("")
self.plainTextEdit.setObjectName("plainTextEdit")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(270, 10, 71, 31))
self.pushButton.setObjectName("pushButton")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(20, 80, 51, 21))
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(20, 99, 51, 21))
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(20, 120, 51, 21))
self.label_3.setObjectName("label_3")
self.label_4 = QtWidgets.QLabel(self.centralwidget)
self.label_4.setGeometry(QtCore.QRect(20, 140, 51, 21))
self.label_4.setObjectName("label_4")
self.label_5 = QtWidgets.QLabel(self.centralwidget)
self.label_5.setGeometry(QtCore.QRect(80, 80, 251, 21))
self.label_5.setText("")
self.label_5.setObjectName("label_5")
self.label_6 = QtWidgets.QLabel(self.centralwidget)
self.label_6.setGeometry(QtCore.QRect(80, 100, 251, 21))
self.label_6.setText("")
self.label_6.setObjectName("label_6")
self.label_7 = QtWidgets.QLabel(self.centralwidget)
self.label_7.setGeometry(QtCore.QRect(80, 120, 251, 21))
self.label_7.setText("")
self.label_7.setObjectName("label_7")
self.label_8 = QtWidgets.QLabel(self.centralwidget)
self.label_8.setGeometry(QtCore.QRect(80, 140, 251, 21))
self.label_8.setText("")
self.label_8.setObjectName("label_8")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(270, 160, 75, 23))
self.pushButton_2.setObjectName("pushButton_2")
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.pushButton.clicked.connect(self.on_search_clicked)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton.setText(_translate("MainWindow", "SEARCH"))
self.label.setText(_translate("MainWindow", "Title:"))
self.label_2.setText(_translate("MainWindow", "Author:"))
self.label_3.setText(_translate("MainWindow", "Views:"))
self.label_4.setText(_translate("MainWindow", "Likes:"))
self.pushButton_2.setText(_translate("MainWindow", "Download"))
#THIS IS THE METHOD THAT I WROTE MYSELF
def on_search_clicked(self):
global link
link = self.plainTextEdit.toPlainText()
global video
video = YouTube(link)
self.label_5.setText(video.title)
self.label_6.setText(video.author)
self.label_7.setText(str(video.views))
self.label_8.setText(str(video.likes))
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_())
The problem is, when I provide a link in the plainTextEdit box and press the pushButton, the application crashes. There must be some problem in on_search_clicked() as it is the only method I wrote and the rest is auto generated.

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