I have the following code which has two classes:
-Ui_dialog_in
-myWindow
What I 'm trying to achieve is:
-when myWindow opens, to open a Ui_dialog_in
What must I change - add?
-Ui_dialog_in
-myWindow
What I 'm trying to achieve is:
-when myWindow opens, to open a Ui_dialog_in
What must I change - add?
from PyQt6 import QtCore, QtGui, QtWidgets
from PyQt6.QtWidgets import QMainWindow, QHBoxLayout, QWidget
from PySide6.QtWidgets import QApplication
class Ui_dialog_in(object):
def setupUi(self, dialog_in):
dialog_in.setObjectName("dialog_in")
dialog_in.resize(400, 146)
self.verticalLayout_3 = QtWidgets.QVBoxLayout(dialog_in)
self.verticalLayout_3.setObjectName("verticalLayout_3")
self.verticalLayout_2 = QtWidgets.QVBoxLayout()
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.verticalLayout = QtWidgets.QVBoxLayout()
self.verticalLayout.setObjectName("verticalLayout")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.titleLabel = QtWidgets.QLabel(dialog_in)
self.titleLabel.setObjectName("titleLabel")
self.horizontalLayout_2.addWidget(self.titleLabel)
self.titleEdit = QtWidgets.QLineEdit(dialog_in)
self.titleEdit.setObjectName("titleEdit")
self.horizontalLayout_2.addWidget(self.titleEdit)
self.horizontalLayout_2.setStretch(0, 1)
self.horizontalLayout_2.setStretch(1, 4)
self.verticalLayout.addLayout(self.horizontalLayout_2)
self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.authorLabel = QtWidgets.QLabel(dialog_in)
self.authorLabel.setObjectName("authorLabel")
self.horizontalLayout_3.addWidget(self.authorLabel)
self.authorNameCombo = QtWidgets.QComboBox(dialog_in)
self.authorNameCombo.setObjectName("authorNameCombo")
self.horizontalLayout_3.addWidget(self.authorNameCombo)
self.horizontalLayout_3.setStretch(0, 1)
self.horizontalLayout_3.setStretch(1, 4)
self.verticalLayout.addLayout(self.horizontalLayout_3)
spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Expanding)
self.verticalLayout.addItem(spacerItem)
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum)
self.horizontalLayout.addItem(spacerItem1)
self.okButton = QtWidgets.QPushButton(dialog_in)
self.okButton.setObjectName("okButton")
self.horizontalLayout.addWidget(self.okButton)
self.pushButton = QtWidgets.QPushButton(dialog_in)
self.pushButton.setObjectName("pushButton")
self.horizontalLayout.addWidget(self.pushButton)
self.verticalLayout.addLayout(self.horizontalLayout)
self.verticalLayout_2.addLayout(self.verticalLayout)
self.verticalLayout_3.addLayout(self.verticalLayout_2)
self.retranslateUi(dialog_in)
QtCore.QMetaObject.connectSlotsByName(dialog_in)
def retranslateUi(self, dialog_in):
_translate = QtCore.QCoreApplication.translate
dialog_in.setWindowTitle(_translate("dialog_in", "Dialog"))
self.titleLabel.setText(_translate("dialog_in", "Title"))
self.authorLabel.setText(_translate("dialog_in", "Author"))
self.okButton.setText(_translate("dialog_in", "PushButton"))
self.pushButton.setText(_translate("dialog_in", "PushButton"))
class myWindow(QMainWindow):
"""A window to show the books available"""
def __init__(self, parent=None):
"""Initializer."""
super().__init__(parent)
self.setWindowTitle("My title")
self.resize(550, 250)
self.centralWidget = QWidget()
self.setCentralWidget(self.centralWidget)
self.layout = QHBoxLayout()
self.centralWidget.setLayout(self.layout)
#self.setupUI()
# open second window, myDialog
myDialog = Ui_dialog_in()
if __name__ == "__main__":
app = QApplication([])
import sys
window = myWindow()
window.resize(800, 600)
window.show()
sys.exit(app.exec())

.