Pyqt5 中 QDialog show 和 exec 的區(qū)別
新手不必深究這個(gè)問題,知道有差別即可。
QDialog的顯示有兩個(gè)函數(shù)show()和exec()。他們的區(qū)別在參考文檔上的解釋如下:
show():
顯示一個(gè)非模式對(duì)話框。控制權(quán)即刻返回給調(diào)用函數(shù)。
彈出窗口是否模式對(duì)話框,取決于modal屬性的值。
原文:Shows the dialog as a modeless dialog. Control returns immediately to the calling code.
The dialog will be modal or modeless according to the value of the modal property.
exec():
顯示一個(gè)模式對(duì)話框,并且鎖住程序直到用戶關(guān)閉該對(duì)話框?yàn)橹?。函?shù)返回一個(gè)DialogCode結(jié)果。
在對(duì)話框彈出期間,用戶不可以切換同程序下的其它窗口,直到該對(duì)話框被關(guān)閉。
原文:Shows the dialog as a modal dialog, blocking until the user closes it. The function returns a DialogCode result.
Users cannot interact with any other window in the same application until they close the dialog.
父類實(shí)例化子類 直接用.show()方法閃退, 所以要實(shí)例化為父類的全局變量 or 執(zhí)行exec_() 方法