参数 1 具有意外类型 'EnumMeta'

argument 1 has unexpected type 'EnumMeta'

我正在尝试显示一个简单的 GUI

# Form implementation generated from reading ui file 'UI/form.ui'
# Created by: PyQt6 UI code generator 6.1.0
# WARNING: Any manual changes made to this file will be lost when pyuic6 
# is run again.  Do not edit this file unless you know what you are doing.


from PyQt6 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(886, 487)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
        self.gridLayout.setObjectName("gridLayout")
        self.Enter = QtWidgets.QPushButton(self.centralwidget)
        self.Enter.setObjectName("Enter")
        self.gridLayout.addWidget(self.Enter, 2, 0, 1, 1)
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setLayoutDirection(QtCore.Qt.LayoutDirection.RightToLeft)
        self.label.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
        self.label.setObjectName("label")
        self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
        self.plainTextEdit = QtWidgets.QPlainTextEdit(self.centralwidget)
        self.plainTextEdit.setObjectName("plainTextEdit")
        self.gridLayout.addWidget(self.plainTextEdit, 1, 0, 1, 1)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 886, 20))
        self.menubar.setObjectName("menubar")
        self.menuFile = QtWidgets.QMenu(self.menubar)
        self.menuFile.setObjectName("menuFile")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.actionUpload = QtGui.QAction(MainWindow)
        self.actionUpload.setShortcutContext(QtCore.Qt.WindowShortcut)
        self.actionUpload.setMenuRole(QtGui.QAction.AboutQtRole)
        self.actionUpload.setObjectName("actionUpload")
        self.menuFile.addAction(self.actionUpload)
        self.menubar.addAction(self.menuFile.menuAction())

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.Enter.setText(_translate("MainWindow", "Enter"))
        self.label.setText(_translate("MainWindow", "Enter Text Below Or Upload File"))
        self.menuFile.setTitle(_translate("MainWindow", "File"))
        self.actionUpload.setText(_translate("MainWindow", "Upload"))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec())

但我明白了 发生异常:TypeError 我再次尝试使用 pyuic6 但无济于事

我正在使用 PyQt6 并且是 运行 基于 Debian Linux 的 OS

如果这段代码是由 pyuic 生成的,那么它就是一个 PyQt 错误。在 PyQt6 中,标志和枚举更严格,因此您必须更改

self.actionUpload.setShortcutContext(QtCore.Qt.WindowShortcut)
self.actionUpload.setMenuRole(QtGui.QAction.AboutQtRole)

至:

self.actionUpload.setShortcutContext(QtCore.Qt.ShortcutContext.WindowShortcut)
self.actionUpload.setMenuRole(QtGui.QAction.MenuRole.AboutQtRole)