2017-03-12 4 views
0

私はPyQTでフォトエディタを作成しています。私はちょうど新しいメインウィンドウをロードする他のエディタのように、 "New"アクションが押されるたびに同じメインpyqtファイルを開くロジックがあるかどうかを知りたかったのです。同じpyqtファイルを開く方法

答えて

0

同じファイルを開く代わりに、ウィンドウをQWidgetとして作成し、毎回新しいウィンドウを作成するだけです。

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_() 
関連する問題