【问题标题】:PyQt5 QLabel errorsPyQt5 QLabel 错误
【发布时间】:2014-04-17 06:14:44
【问题描述】:

在 PyQT4 中有一个 QLabel()

当我在 PyQT5 中使用它时,它会抛出一个未定义的错误。

谁能告诉我 PyQT4 中的 Qlabel 是什么?

或者我错了?

这是我的代码:

import sys
import time
from PyQt5.QtCore import *
from PyQt5.QtGui import *

app = QGuiApplication(sys.argv)
try:
    due = QTime.currentTime()
    message = "Alert!"
    if len(sys.argv) < 2 :
        raise ValueError
    hours, min = sys.argv[1].split(":")
    due = Qtime(int(hours), int(min))
    if not due.isValid():
        raise ValueError
    if len(sys.argv) > 2 :
        message = " ".join(sys.argv[2:])
except ValueError :
    message = "Alert: alert.pyw"

if QTime.currentTime() < due :
    time.sleep(20) #20 Seconds
label = QLabel("<p>Message</p>")

【问题讨论】:

  • 您能否更具体地解释导致它在 PyQT5 中引发错误但在 PyQT4 中没有引发错误的情况。 QLabel() 在两个版本中都有定义:PyQT5PyQT4
  • 你能显示所有可以启动的代码吗?

标签: python pyqt4 pyqt5


【解决方案1】:

您应该阅读我发布的docs。将此导入语句与其他语句一起添加:

from PyQt5.QtWidgets import *

【讨论】:

    【解决方案2】:

    由于 QLabel() 在 PyQt5.QtWidgets 中,请尝试以下操作: 从 PyQt5.QtWidgets 导入 QLabel

    【讨论】:

      猜你喜欢
      • 2019-01-22
      • 2017-03-07
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      • 2019-04-06
      • 1970-01-01
      • 2019-04-23
      • 2020-12-18
      相关资源
      最近更新 更多