python - 无法在 PyQt4 上显示 Qlabel

标签 python user-interface pyqt4 qlabel

您好,我发布了下面的代码,通过该代码我无法在 pyqt4 中显示标签。任何建议都会有帮助。

from PyQt4 import QtGui
from PyQt4 import QtCore
import sys

class Entry_view(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.setGeometry(25, 25, 800, 480)

        label = QtGui.QLabel()
        label.setText("Welcome To Python GUI")
        label.resize(100, 50)
        # label.show(self)
        self.show()


if __name__ == '__main__':
app     = QtGui.QApplication(sys.argv)
myapp = Entry_view()
sys.exit(app.exec_())

最佳答案

您没有保留对标签的引用,因此它在显示之前就被垃圾收集了。试试这个:

self.label = QtGui.QLabel(self)
self.label.setText("Welcome To Python GUI")
self.label.resize(100, 50)

关于python - 无法在 PyQt4 上显示 Qlabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41484668/

相关文章:

python - 使用命名空间解析 XML 时出现问题

Python Scrapy XPathSelector

python - PyQt Qtableview背景颜色基于文本值而不是True或False

python - PyQt:多个 QProcess 和输出

python - 在Python中循环创建和覆盖数据框(列表)

python - 如何减少python中的多个if语句

.net - WinForms - 事件指示器

c# - "Ø"作为 C# 中的输入

android - android中从右到左的布局

python - 从 pyqt4 python 中的类调用paintEvent()