【问题标题】:Unable to display the label after the button is clicked In python using PyQt5 [duplicate]单击按钮后无法显示标签在python中使用PyQt5 [重复]
【发布时间】:2020-03-29 08:27:58
【问题描述】:

按钮正在调用 clickMethod 函数,因为它在控制台中显示“您单击了 PushButton”,但未显示标签

import sys

import self as self
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QLineEdit, QPushButton
from PyQt5.uic.properties import QtWidgets

if __name__ == "__main__":
    app = QApplication([])
    w = QWidget()
    VideoUrl = QLabel(w)
    VideoUrl.setText('videoURL')
    VideoUrl.move(100, 40)
    InputText = QLineEdit(w)
    InputText.move(100, 60)
    Button = QPushButton(w)
    Button.setText('Download')
    Button.move(100, 100)


def clickMethod():
    print("You clicked PushButton")
    output = QLabel(w)
    output.setText("clicked")
    output.move(100, 70)


Button.clicked.connect(clickMethod)

w.resize(700, 500)

w.show()
sys.exit(app.exec_())

【问题讨论】:

  • 对代码逻辑要更加小心。如果您随后引用可能仅在此处创建的对象,则针对 name 进行测试没有多大意义:如果 __name__ 不同(例如,如果您尝试导入文件),@ 987654323@、wButton 将不存在,您的程序将崩溃。
  • 感谢您的输入,您能否提供替代解决方案,例如文档

标签: python pyqt5


【解决方案1】:

尝试在 clickMethod 末尾添加ouput.show()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-08
    • 1970-01-01
    • 2018-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多