Q&A
環境
- Windows10
- Python3.6.3
関係するコード
次のようなコードを書いています。メインウィンドウが最初に表示され、メニューバーSettingのPathを押すとSetPath
クラスが動いて新しいウィンドウが立ちあがるようなものを考えています。
Python
1from PyQt5.QtWidgets import (QAction, QApplication, QGridLayout, QHBoxLayout, QMainWindow, QMessageBox, 2 QLabel, QLineEdit, QPushButton, QTextEdit, QVBoxLayout, QWidget) 3 4class MainWindow(QMainWindow): 5 6 def __init__(self): 7 super().__init__() 8 self.initUI() 9 if DataBase.FilePath().is_empty(): 10 self.SetFilePath() 11 12 def initUI(self): 13 """WIdgetの配置に関する記述""" 14 15 pathAction = QAction('Path', self) 16 pathAction.triggered.connect(self.SetFilePath) 17 18 menubar = self.menuBar() 19 pathmenu = menubar.addMenu('&Setting') 20 pathmenu.addAction(pathAction) 21 22 def SetFilePath(self): 23 import sys 24 25 popup_path = QApplication(sys.argv) 26 ex = SetPath() 27 sys.exit(popup_path.exec_()) 28 29 30class SetPath(QWidget): 31 def __init__(self): 32 super().__init__() 33 self.initUI() 34 35 def initUI(self): 36 """新しいウィンドウのウィジットに関する記述""" 37 38if __name__ == '__main__': 39 import sys 40 app = QApplication(sys.argv) 41 ex = MainWindow() 42 sys.exit(app.exec_())
解決したい問題
最初は知らせたときには正常にMainWindow
が立ち上がります。しかし、メニューバー中のPathを押すと新しいウィンドウが一瞬立ち上がったのち、ウィンドウが2つとも消えてしまいます。原因がわからなくて困っているので、解決法をご教授していただきたいです。
回答1件
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
2018/03/18 14:19