简体   繁体   中英

How to open same pyqt file again

I am creating a photo editor in PyQT. I just wanted to know is there any logic to open same main pyqt file whenever "New" action is pressed as in other editors which loads new window new action is pressed.

Instead of opening the same file, create the window as a QWidget and just create a new window every time.

from PyQt5 import QtWidgets

app = QtWidgets.QApplication([])
main_window = QtWidgets.QWidget()
# created the editor as a QPlainTextEdit for demo, could be any QWidget, even your class that extends it
editor = QtWidgets.QPlainTextEdit()

layout = QtWidgets.QVBoxLayout()
btn = QtWidgets.QPushButton("abrir")
btn.clicked.connect(editor.show)
layout.addWidget(btn)
main_window.setLayout(layout)
main_window.show()

if __name__ == "__main__":
    app.exec_()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM