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

        • <bdo id='fE561'></bdo><ul id='fE561'></ul>

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

      1. Pyinstaller 和 PyQt5 macOS Mojave 兼容性问题

        时间:2023-08-04
          <tbody id='CFKzK'></tbody>

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

          <tfoot id='CFKzK'></tfoot>

            1. <i id='CFKzK'><tr id='CFKzK'><dt id='CFKzK'><q id='CFKzK'><span id='CFKzK'><b id='CFKzK'><form id='CFKzK'><ins id='CFKzK'></ins><ul id='CFKzK'></ul><sub id='CFKzK'></sub></form><legend id='CFKzK'></legend><bdo id='CFKzK'><pre id='CFKzK'><center id='CFKzK'></center></pre></bdo></b><th id='CFKzK'></th></span></q></dt></tr></i><div id='CFKzK'><tfoot id='CFKzK'></tfoot><dl id='CFKzK'><fieldset id='CFKzK'></fieldset></dl></div>
                <bdo id='CFKzK'></bdo><ul id='CFKzK'></ul>
                <legend id='CFKzK'><style id='CFKzK'><dir id='CFKzK'><q id='CFKzK'></q></dir></style></legend>
                  本文介绍了Pyinstaller 和 PyQt5 macOS Mojave 兼容性问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  在我从 High Sierra 升级到 Mojave 之前,我使用 Pyinstaller 创建的应用程序运行良好.为了演示这个问题,我创建了一个简单的应用程序.主窗口只有一个按钮.当您按下按钮时,其文本应更改为请稍候"10 秒钟.当我将此程序作为 .py 脚本运行时,一切正常,但在使用 Pyinstaller 创建 .app 文件后,它的行为会有所不同.在您单击窗口外的任何位置之前,文本不会更新.

                  My application, created with Pyinstaller, worked fine until I upgraded from High Sierra to Mojave. In order to demonstrate the issue I create the simple application. Main window has only one button. When you press the button its text should be changed to "Please wait" for 10 seconds. When I run this program as .py script, everything works fine, but after creating .app file with Pyinstaller it behaves differently. The text is not updated until you click anywhere outside of the window.

                  我尝试重新安装 Pyinstaller,但问题仍然存在.

                  I tried to reinstall Pyinstaller, but the problem still exists.

                  from PyQt5 import QtCore, QtGui, QtWidgets
                  import time
                  
                  class Ui_MainWindow(object):
                      def setupUi(self, MainWindow):
                          MainWindow.setObjectName("MainWindow")
                          MainWindow.resize(303, 304)
                          self.centralwidget = QtWidgets.QWidget(MainWindow)
                          self.centralwidget.setObjectName("centralwidget")
                          self.label = QtWidgets.QLabel(self.centralwidget)
                          self.label.setGeometry(QtCore.QRect(50, 80, 300, 43))
                          self.pushButton = QtWidgets.QPushButton(self.centralwidget)
                          self.pushButton.setGeometry(QtCore.QRect(80, 170, 113, 32))
                          self.pushButton.setObjectName("pushButton")
                          self.pushButton.setDefault(True)
                          MainWindow.setCentralWidget(self.centralwidget)
                  
                          self.retranslateUi(MainWindow)
                          QtCore.QMetaObject.connectSlotsByName(MainWindow)
                  
                          self.pushButton.clicked.connect(self.click)
                          self.thread = Thread()
                          self.thread.finished.connect(lambda: self.pushButton.setEnabled(True))
                  
                  
                      def retranslateUi(self, MainWindow):
                          _translate = QtCore.QCoreApplication.translate
                          MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
                          self.pushButton.setText(_translate("MainWindow", "Click me"))
                  
                  
                      def click(self):
                          if not self.thread.isRunning():
                              self.pushButton.setEnabled(False)
                              self.pushButton.setText("Please wait")
                              self.label.setText("The button below should display 
                   'Please wait' for 10 seconds")
                              self.thread.start()
                  
                  class Thread(QtCore.QThread):
                      def run(self):
                  
                          time.sleep(10)
                          ui.pushButton.setEnabled(False)
                          ui.pushButton.setText("Click me") 
                          ui.label.setText("")
                  
                  
                  
                  if __name__ == "__main__":
                      import sys
                      app = QtWidgets.QApplication(sys.argv)
                      MainWindow = QtWidgets.QMainWindow()
                      ui = Ui_MainWindow()
                      ui.setupUi(MainWindow)
                      MainWindow.show()
                      sys.exit(app.exec_())
                  

                  推荐答案

                  我找到了我的问题的答案.为了解决这个渲染问题,您需要为需要更新的 ui 元素添加以下行.就我而言,仅当我需要在 macOS Mojave 上运行此应用程序时才需要它.

                  I found an answer to my question. In order to solve this rendering issue you need to add the following line for a ui element, which needs to be updated. In my case it is required only if I need to run this application on macOS Mojave.

                  <element>.repaint()

                  例如:

                  def click(self):             
                          self.pushButton.setEnabled(False)
                          self.pushButton.setText("Button is clicked...")
                          self.pushButton.repaint()
                  

                  这篇关于Pyinstaller 和 PyQt5 macOS Mojave 兼容性问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:单击菜单标题时连接功能 下一篇:如何从 qdateEdit 获取用户输入并从 postgres 的数据

                  相关文章

                  最新文章

                • <legend id='3b2J2'><style id='3b2J2'><dir id='3b2J2'><q id='3b2J2'></q></dir></style></legend>

                • <i id='3b2J2'><tr id='3b2J2'><dt id='3b2J2'><q id='3b2J2'><span id='3b2J2'><b id='3b2J2'><form id='3b2J2'><ins id='3b2J2'></ins><ul id='3b2J2'></ul><sub id='3b2J2'></sub></form><legend id='3b2J2'></legend><bdo id='3b2J2'><pre id='3b2J2'><center id='3b2J2'></center></pre></bdo></b><th id='3b2J2'></th></span></q></dt></tr></i><div id='3b2J2'><tfoot id='3b2J2'></tfoot><dl id='3b2J2'><fieldset id='3b2J2'></fieldset></dl></div>
                    <bdo id='3b2J2'></bdo><ul id='3b2J2'></ul>

                • <small id='3b2J2'></small><noframes id='3b2J2'>

                • <tfoot id='3b2J2'></tfoot>