(六 Widget-4)Pyqt5 中 exec_() show() 区别

Pyqt5 中 QDialog show 和 exec 的区别

新手不必深究这个问题,知道有差别即可。

QDialog的显示有两个函数show()和exec()。他们的区别在参考文档上的解释如下:

show():
显示一个非模式对话框。控制权即刻返回给调用函数。
弹出窗口是否模式对话框,取决于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():
显示一个模式对话框,并且锁住程序直到用户关闭该对话框为止。函数返回一个DialogCode结果。
在对话框弹出期间,用户不可以切换同程序下的其它窗口,直到该对话框被关闭。
原文: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.

父类实例化子类 直接用.show()方法闪退, 所以要实例化为父类的全局变量 or 执行exec_() 方法

参考链接

你可能感兴趣的:((六 Widget-4)Pyqt5 中 exec_() show() 区别)