• 카테고리

    질문 & 답변
  • 세부 분야

    데이터 분석

  • 해결 여부

    미해결

AuthDialog 질문입니다.

20.08.20 02:07 작성 조회수 72

0

AuthDialog.py 를 만들고 Main에서 다음과 같이 불러올 때

    @pyqtSlot() 
    def authCheck(self) :
        dlg = AuthDialog()
        dlg.exec_()

dlg.show() 없이 창이 띄어집니다.

이 이유가 
if __name__ == "__main__" :  에서 
you_viewer_main = Main()  #Class Main
you_viewer_main.show()


전체를 한번 show() 해줘서 가능한 건가요?

답변 1

답변을 작성해보세요.

1

안녕하세요.

exec_() 자체가 이벤트 루프를 생성하므로, 창이 보여지게 됩니다.

app.exec_() does not lock anything, it runs a GUI event loop that waits for user actions (events) and dispatches them to the right widget for handling. It does this until there are no top level windows left open; if you leave at least one top level window of your app open, then exec() never returns, it can't (your app will be terminated during system shutdown). When no more top level windows the app cleans up and returns from exec(). At that point the GUI is no longer in the event loop.

Whatever it is you want to do after exec() it is likely you would either put it in a QThread or in a signal handler (which you would connect, for example, to a "Go!" button; you would connect a "Cancel" button to a handler that closes the app window).

You can put code after exec() but it would be rather unconventional: if anything goes wrong it is unlikely that user can see the problem since the GUI is no longer visible, a GUI app doesn't usually have a console terminal open where the error might be seen, there will not typically be a console for a GUI app (ie you will run the app via pythonw.exe instead of python.exe), or you have to open a new window and exec() again in order to show an error message and wait till user clicks ok, destroy message window in ok handler so app.exec() once again returns.