Python Forum
Close and Open QDialog from QDialog 2
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Close and Open QDialog from QDialog 2
#4
A simple example to open dialog1 on closing dialog2

from PyQt5.QtWidgets import (QMainWindow, QApplication, 
                             QPushButton, QDialog)

class firstDialog(QDialog):
    def __init__(self, parent = None):
        super(firstDialog, self).__init__(parent)
        self.setGeometry(250, 250, 300, 100)
        self.setWindowTitle("Dialog 1")

       
class secondDialog(QDialog):
    def __init__(self, parent = None):
        super(secondDialog, self).__init__(parent)
        self.setGeometry(100, 100, 300, 100)
        self.setWindowTitle("Dialog 2")
                   
    def closeEvent(self, event):
        print("closing secondDialog\n\nopening firstDialog")
        self.firstdial= firstDialog()
        self.firstdial.show()
        event.accept()
            
class mainWin(QMainWindow):
    def __init__(self, parent = None):
        super(mainWin, self).__init__(parent)
        self.setupUI()
        
    def setupUI(self):
        self.setGeometry(0, 0, 400, 300)
        self.tb = self.addToolBar("TB")
        dialog_btn_1 = QPushButton("show Dialog")
        dialog_btn_1.clicked.connect(self.show_dlg)
        self.tb.addWidget(dialog_btn_1)

        
    def show_dlg(self):
        self.dlg = secondDialog()
        self.dlg.show()


if __name__ == '__main__':
    import sys
    app = QApplication(sys.argv)
    win = mainWin()
    win.setWindowTitle("Main Window")
    win.show()

    sys.exit(app.exec_())
Reply


Messages In This Thread
Close and Open QDialog from QDialog 2 - by ITSRL - Jul-11-2022, 01:31 PM
RE: Close and Open QDialog from QDialog 2 - by Axel_Erfurt - Jul-11-2022, 05:04 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How To Find an Opening and Closing String, Copying Open/Close/Contents to New File davidshq 1 2,029 Mar-03-2020, 04:47 AM
Last Post: davidshq
  How can I Open and close .py file from python scripts SayHiii 9 5,732 Dec-17-2019, 06:10 AM
Last Post: Malt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020