2017-10-24 8 views
0

〜EDIT(元の質問はまだ下です)〜新しいウィンドウでself.setGeometry()呼び出しを削除すると、正常に動作します。何故ですか?私はまだそれのためのUIを構築していますが、私は私がこの問題を抱え続けていないことを願っています...PyQt5で新しいウィンドウを開くときに自分のアプリが閉じるのはなぜですか?

〜EDIT 2〜それはself.resize()自己でなければならないことを実現しました。 setGeometry()...

self.solved() 

:(

私はちょうどPyQt5を学び、ちょうどいじり少しやっている。何らかの理由で、私は、メインアプリケーションウィンドウから新しいウィンドウを開こうとすると、進行状況を追跡するためにいくつかのprintステートメントを入れると、実際に新しいウィンドウを作成していないことが示されます。

メインウィンドウコード:ここで

import sys 
from PyQt5.QtWidgets import QMainWindow, QAction, QApplication 
from newLeague import * 


class MainWindow(QMainWindow): 

    def __init__(self): 
     super(MainWindow, self).__init__() 

     newLeagueAction = QAction('Create New League', self) 
     newLeagueAction.setShortcut('Ctrl+N') 
     newLeagueAction.setStatusTip('Create a new league from scratch') 
     newLeagueAction.triggered.connect(self.createNewLeague) 

     openLeagueAction = QAction('Open Existing League', self) 
     openLeagueAction.setShortcut('Ctrl+E') 
     openLeagueAction.setStatusTip('Continue with a previously started league') 
     openLeagueAction.triggered.connect(self.openExistingLeague) 

     exitAction = QAction('Quit', self) 
     exitAction.setShortcut('Ctrl+Q') 
     exitAction.setStatusTip('Quit the application...') 
     exitAction.triggered.connect(self.close) 

     self.statusBar() 

     mainMenu = self.menuBar() 
     fileMenu = mainMenu.addMenu('&File') 
     fileMenu.addAction(newLeagueAction) 
     fileMenu.addAction(openLeagueAction) 
     fileMenu.addAction(exitAction) 

     self.resize(1920, 1080) 
     self.setWindowTitle("Brackets") 

    def createNewLeague(self): 
     '''shows dialog to create a new league''' 

     self.newLeague = CreateLeague() 
     self.newLeague.show() 
     print('New League being created...') 

    def openExistingLeague(self): 
     print('Existing League opening...') 


def main(): 
    app = QApplication(sys.argv) 
    window = MainWindow() 
    window.show() 
    sys.exit(app.exec_()) 

if __name__ == '__main__': 
    main() 

は、第二の窓です:

from PyQt5.QtWidgets import QMainWindow 


class CreateLeague(QMainWindow): 
    def __init__(self): 
     super(CreateLeague, self).__init__() 

     self.initUI() 

    def initUI(self): 
     self.setGeometry(600, 500) 
     self.setWindowTitle('Create A New League') 

私は、このようなthis、およびthisなどの他の例を見てきた、と私はそれが私が何であるかを見ていませんよ別のことをしている。私は、コンストラクタでparentを引数として使用して実験しましたが、結果は変わりません。

答えて

0

メインウィンドウのコードは問題ありませんが、第2のウィンドウのsuperパラメータからCreateLeague, self引数を削除して、コードを正常に動作させる必要があります。

は、以下を参照してください。

from PyQt5.QtWidgets import QMainWindow 
class CreateLeague(QMainWindow): 
    def __init__(self): 
     super().__init__() 

     self.initUI() 

    def initUI(self): 
     self.resize(600, 500) 
     self.setWindowTitle('Create A New League') 
関連する問題