<legend id='6GF5s'><style id='6GF5s'><dir id='6GF5s'><q id='6GF5s'></q></dir></style></legend>

        <i id='6GF5s'><tr id='6GF5s'><dt id='6GF5s'><q id='6GF5s'><span id='6GF5s'><b id='6GF5s'><form id='6GF5s'><ins id='6GF5s'></ins><ul id='6GF5s'></ul><sub id='6GF5s'></sub></form><legend id='6GF5s'></legend><bdo id='6GF5s'><pre id='6GF5s'><center id='6GF5s'></center></pre></bdo></b><th id='6GF5s'></th></span></q></dt></tr></i><div id='6GF5s'><tfoot id='6GF5s'></tfoot><dl id='6GF5s'><fieldset id='6GF5s'></fieldset></dl></div>
          <bdo id='6GF5s'></bdo><ul id='6GF5s'></ul>
      1. <tfoot id='6GF5s'></tfoot>

      2. <small id='6GF5s'></small><noframes id='6GF5s'>

        我应该在我的 PyQt 应用程序中使用 `app.exec()` 还是

        时间:2023-08-05

          <legend id='beG1C'><style id='beG1C'><dir id='beG1C'><q id='beG1C'></q></dir></style></legend>

          <small id='beG1C'></small><noframes id='beG1C'>

            <tbody id='beG1C'></tbody>

                <bdo id='beG1C'></bdo><ul id='beG1C'></ul>

                • <i id='beG1C'><tr id='beG1C'><dt id='beG1C'><q id='beG1C'><span id='beG1C'><b id='beG1C'><form id='beG1C'><ins id='beG1C'></ins><ul id='beG1C'></ul><sub id='beG1C'></sub></form><legend id='beG1C'></legend><bdo id='beG1C'><pre id='beG1C'><center id='beG1C'></center></pre></bdo></b><th id='beG1C'></th></span></q></dt></tr></i><div id='beG1C'><tfoot id='beG1C'></tfoot><dl id='beG1C'><fieldset id='beG1C'></fieldset></dl></div>
                • <tfoot id='beG1C'></tfoot>
                  本文介绍了我应该在我的 PyQt 应用程序中使用 `app.exec()` 还是 `app.exec_()`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我使用 Python 3 和 PyQt5.这是我的测试 PyQt5 程序,关注最后两行:

                  I use Python 3 and PyQt5. Here's my test PyQt5 program, focus on the last 2 lines:

                  from PyQt5.QtCore import *
                  from PyQt5.QtWidgets import *
                  import sys
                  
                  class window(QWidget):
                  def __init__(self,parent=None):
                      super().__init__(parent)
                      self.setWindowTitle('test')
                      self.resize(250,200)
                  
                  app=QApplication(sys.argv)
                  w=window()
                  w.show()
                  sys.exit(app.exec())
                  #sys.exit(app.exec_())
                  

                  我知道 exec 是 Python 中的语言关键字.但是 Official PyQt5 Documentation 上的代码(特别是 Object Destruction on Exit 部分).我看到该示例显示了 app.exec() 的使用,这让我感到困惑.

                  I know exec is a language keyword in Python. But code on Official PyQt5 Documentation (specifically the Object Destruction on Exit part). I see that example shows use of app.exec() which confuses me.

                  当我在我的机器上测试它时.我发现与我的结局没有任何明显的区别.使用和不使用 _ 都会在没有时间差的情况下产生相同的输出.

                  When I tested it on my machine. I found there is no any visible difference from my end. Both with and without _ produces the same output in no time difference.

                  我的问题是:

                  • 我使用 app.exec() 有什么问题吗?喜欢与 Python 的内部 exec 冲突?我怀疑是因为两个 exec 都在执行某些东西.
                  • 如果不能,我可以同时使用两者吗?
                  • Is there anything wrong going when I use app.exec()? like clashing with Python's internal exec? I suspect because both exec's are executing something.
                  • If not, can I use both interchangeably?

                  推荐答案

                  那是因为在 Python 3 之前,exec 是一个保留关键字,因此 PyQt 开发人员为其添加了下划线.从 Python 3 开始,exec 不再是保留关键字(因为它是一个内置函数;与 print 的情况相同),所以在 PyQt5 中提供一个不带下划线的版本以与 C++ 文档保持一致是有意义的,但保留一个带下划线的版本是为了向后兼容.所以对于带有 Python 3 的 PyQt5,这两个 exec 函数是相同的.对于较旧的 PyQt,只有 exec_() 可用.

                  That's because until Python 3, exec was a reserved keyword, so the PyQt devs added underscore to it. From Python 3 onwards, exec is no longer a reserved keyword (because it is a builtin function; same situation as print), so it made sense in PyQt5 to provide a version without an underscore to be consistent with C++ docs, but keep a version with underscore for backwards compatibility. So for PyQt5 with Python 3, the two exec functions are the same. For older PyQt, only exec_() is available.

                  这篇关于我应该在我的 PyQt 应用程序中使用 `app.exec()` 还是 `app.exec_()`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何使用 PyQt5 设置窗口图标? 下一篇:Python PyQt5:如何使用 PyQt5 显示错误消息

                  相关文章

                  最新文章

                  <i id='7tPEG'><tr id='7tPEG'><dt id='7tPEG'><q id='7tPEG'><span id='7tPEG'><b id='7tPEG'><form id='7tPEG'><ins id='7tPEG'></ins><ul id='7tPEG'></ul><sub id='7tPEG'></sub></form><legend id='7tPEG'></legend><bdo id='7tPEG'><pre id='7tPEG'><center id='7tPEG'></center></pre></bdo></b><th id='7tPEG'></th></span></q></dt></tr></i><div id='7tPEG'><tfoot id='7tPEG'></tfoot><dl id='7tPEG'><fieldset id='7tPEG'></fieldset></dl></div>
                  <tfoot id='7tPEG'></tfoot>
                  <legend id='7tPEG'><style id='7tPEG'><dir id='7tPEG'><q id='7tPEG'></q></dir></style></legend>

                    <small id='7tPEG'></small><noframes id='7tPEG'>

                    • <bdo id='7tPEG'></bdo><ul id='7tPEG'></ul>