【发布时间】: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@、w和Button将不存在,您的程序将崩溃。 -
感谢您的输入,您能否提供替代解决方案,例如文档