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?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
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 ()) |