Click here to Skip to main content
15,895,538 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QDialog, QTreeView, QFileSystemModel
from PyQt5.QtCore import QModelIndex
import sys

class MyWindow(QWidget):
    def __init__(self):
        super(MyWindow, self).__init__()
        self.setGeometry(200, 200, 300, 300)
        self.initUI()

    def initUI(self):    
        self.b1 = QtWidgets.QPushButton(self)
        self.b1.setText("First")
        self.b1.clicked.connect(self.openSecondDialog)
        self.b1.setGeometry(30, 130, 100, 30)

class SecondDialog(MyWindow):
    def __init__(self):
        super(SecondDialog, self).__init__()

    def openSecondDialog(self):
        self.myDialog = QDialog(self)
        self.myDialog.setGeometry(600, 100, 500, 500)
        self.b2 = QtWidgets.QPushButton(self)
        self.b2.setText("Second")
        self.myDialog.show()

def window():
    app = QApplication(sys.argv)
    win = SecondDialog()

    win.show()
    sys.exit(app.exec_())
window()


What I have tried:

In this code, I have a window that has one button named First. When I press it, the second window appears. The problem that I am facing is to put the second button in the second window but it is not appearing in it.
I made two classes to add other features in another window separately.
Posted
Comments
Richard MacCutchan 16-Jan-21 4:52am    
You create the button but I do not see any code to place it on the dialog window.
[no name] 16-Jan-21 12:35pm    
I think you have your windows mixed up in terms of who calls what.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900