首页 > 解决方案 > PyQt5 QLabel 文本没有改变?

问题描述

考虑这个最小的代码片段:

from PyQt5.QtWidgets import QApplication,QWidget,QLabel

app=QApplication([])
w=QWidget()
l=QLabel(w)
l.setText("Ready")
w.show()

def load():
    l.setText('Loading...')
    some_function()
    l.setText('Loaded')

load()

此处所需的输出是QLabel文本应首先更改为“正在加载...”,然后在 some_function() 完成任务后,应更改为“已加载”

但这不是它的工作方式。“正在加载...”文本永远不会出现。在 some_function() 完成后,它直接从“Ready”跳转到“Loaded”。为什么会这样?

标签: python-3.xpyqt5

解决方案


推荐阅读