对于我的PyQT5应用程序,我正在执行一个大型的DataFrame快速应用程序,这可能需要很短的时间。在这段时间内,我的应用程序在窗口标题栏中显示了“(未响应)”消息。
快速应用程序在后台运行时-在控制台中显示如下: documentation
是否可以从swifter中提取当前百分比并将其传递到百分比栏?
代码的简化版本(具有进度条,但仅在范围循环中显示):
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QProgressDialog
from PyQt5.QtCore import pyqtSlot
import pandas as pd
import numpy as np
import swifter
class App(QWidget):
def __init__(self):
super().__init__()
self.title = 'PyQt5 button - pythonspot.com'
self.left = 10
self.top = 10
self.width = 320
self.height = 200
self.initUI()
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
button = QPushButton('PyQt5 button', self)
button.setToolTip('This is an example button')
button.move(100, 70)
button.clicked.connect(self.on_click)
self.show()
@pyqtSlot()
def on_click(self):
df = pd.DataFrame(np.random.randint(0, 100, size=(10000, 4)), columns=list('ABCD'))
#swifter call below stops gui with high computation and would like to extract percentage from.
df['A'] = df.A.swifter.progress_bar(True).apply(getx)
self.progress_bar()
def progress_bar(self):
percentage = QProgressDialog(self)
percentage.show()
for x in range(0,100):
percentage.setValue(x+1)
percentage.close()
def getx(x):
x = np.random.randint(0, 100000)
return x
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())