I'm trying to create a simple GUI using PyQt5, but whenever I run the program. all it displays is a blank window. How can get elements such as a pushbutton or the QLineEdit to actually appear in the window?
Any pointers would be appreciated as I am trying to create an application that can take a user input (a badge and ticket number in this case) then query a database for the tube properties and quantities before displaying the information as an output.
from PyQt5 import QtCore, QtWidgets
class Ui_MainWindow(object):
def __init__(self):
self.title = 'Tube Bender UI'
self.description = QtWidgets.QLabel('New Order Available')
self.badge = QtWidgets.QLineEdit()
self.ticket = QtWidgets.QLineEdit()
self.tubes = 0
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 641)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
MainWindow.setSizePolicy(sizePolicy)
MainWindow.setMaximumSize(QtCore.QSize(800, 641))
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setMinimumSize(QtCore.QSize(800, 641))
self.centralwidget.setMaximumSize(QtCore.QSize(800, 641))
self.centralwidget.setObjectName("centralwidget")
self.horizontalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
self.horizontalLayoutWidget.setGeometry(QtCore.QRect(0, 320, 801, 641))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.horizontalLayoutWidget.sizePolicy().hasHeightForWidth())
#tubes = 0
def coil_id(self):
QtWidgets.QLineEdit(self)
return self.ticket
def page_description(self):
QtWidgets.QLineEdit(self)
return self.description
def page_title(self):
QtWidgets.QLineEdit(self)
return self.title
def badge_id(self):
QtWidgets.QLineEdit(self)
return self.badge
def tube_count(self):
QtWidgets.QLineEdit(self)
print(self.tubes)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
MainPage = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show())
sys.exit(app.exec_()
MainPage = QtWidgets.QMainWindow()
? – Mad PhysicistQLineEdit
andQPushButton
to the Window – tushortzQtWidgets.QLineEdit(self)
? That just creates a new object every time, and doesn't even destroy it because you have assigned it a parent and thus transferred ownership to Qt. – Mad Physicist