<tfoot id='t1fo1'></tfoot>

    <small id='t1fo1'></small><noframes id='t1fo1'>

    • <bdo id='t1fo1'></bdo><ul id='t1fo1'></ul>

    1. <legend id='t1fo1'><style id='t1fo1'><dir id='t1fo1'><q id='t1fo1'></q></dir></style></legend>

      1. <i id='t1fo1'><tr id='t1fo1'><dt id='t1fo1'><q id='t1fo1'><span id='t1fo1'><b id='t1fo1'><form id='t1fo1'><ins id='t1fo1'></ins><ul id='t1fo1'></ul><sub id='t1fo1'></sub></form><legend id='t1fo1'></legend><bdo id='t1fo1'><pre id='t1fo1'><center id='t1fo1'></center></pre></bdo></b><th id='t1fo1'></th></span></q></dt></tr></i><div id='t1fo1'><tfoot id='t1fo1'></tfoot><dl id='t1fo1'><fieldset id='t1fo1'></fieldset></dl></div>

        AttributeError:模块“PyQt5.QtGui"没有属性“QWidg

        时间:2023-08-05
          <bdo id='EIck1'></bdo><ul id='EIck1'></ul>

          • <legend id='EIck1'><style id='EIck1'><dir id='EIck1'><q id='EIck1'></q></dir></style></legend>
              <tbody id='EIck1'></tbody>

            <tfoot id='EIck1'></tfoot>
          • <small id='EIck1'></small><noframes id='EIck1'>

              <i id='EIck1'><tr id='EIck1'><dt id='EIck1'><q id='EIck1'><span id='EIck1'><b id='EIck1'><form id='EIck1'><ins id='EIck1'></ins><ul id='EIck1'></ul><sub id='EIck1'></sub></form><legend id='EIck1'></legend><bdo id='EIck1'><pre id='EIck1'><center id='EIck1'></center></pre></bdo></b><th id='EIck1'></th></span></q></dt></tr></i><div id='EIck1'><tfoot id='EIck1'></tfoot><dl id='EIck1'><fieldset id='EIck1'></fieldset></dl></div>

                1. 本文介绍了AttributeError:模块“PyQt5.QtGui"没有属性“QWidget"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  所以,我正在尝试为我拥有的 python 代码制作 UI,但不断遇到问题......

                  So, I'm trying to make a UI for a python code I have, but keep stumbling up on problems...

                  现在,代码所做的只是创建一个带有 2 个文本编辑器框和一个按钮的窗口.按下按钮时,它会打印测试".

                  Right now, all the code does is make a window, with 2 texteditor boxes, and one button. When the button is pressed, it prints 'Test'.

                  我使用 QTDesigner 制作 UI,然后使用 PyQt5 将其转换为 python,并编辑了代码.

                  I used QTDesigner to make the UI, then PyQt5 to convert it to python, and edited the code.

                  我的代码:

                     # -*- coding: utf-8 -*-
                  
                  # Form implementation generated from reading ui file 'widget.ui'
                  #
                  # Created by: PyQt5 UI code generator 5.9
                  #
                  # WARNING! All changes made in this file will be lost!
                  
                  from PyQt5 import QtCore, QtGui, QtWidgets
                  
                  class Ui_Widget(QtGui.QWidget):
                      def setupUi(self, Widget):
                          Widget.setObjectName("Widget")
                          Widget.resize(681, 382)
                          self.horizontalLayout = QtWidgets.QHBoxLayout(Widget)
                          self.horizontalLayout.setContentsMargins(11, 11, 11, 11)
                          self.horizontalLayout.setSpacing(6)
                          self.horizontalLayout.setObjectName("horizontalLayout")
                          self.in_box = QtWidgets.QTextEdit(Widget)
                          self.in_box.setMaximumSize(QtCore.QSize(200, 350))
                          self.in_box.setObjectName("in_box")
                          self.horizontalLayout.addWidget(self.in_box)
                          self.convert = QtWidgets.QPushButton(Widget)
                          self.convert.setObjectName("convert")
                          self.horizontalLayout.addWidget(self.convert)
                          self.gridLayout = QtWidgets.QGridLayout()
                          self.gridLayout.setContentsMargins(11, 11, 11, 11)
                          self.gridLayout.setSpacing(6)
                          self.gridLayout.setObjectName("gridLayout")
                          self.out_box = QtWidgets.QTextEdit(Widget)
                          self.out_box.setMaximumSize(QtCore.QSize(200, 350))
                          self.out_box.setObjectName("out_box")
                          self.gridLayout.addWidget(self.out_box, 6, 0, 1, 1)
                          self.horizontalLayout.addLayout(self.gridLayout)
                  
                          self.retranslateUi(Widget)
                          QtCore.QMetaObject.connectSlotsByName(Widget)
                  
                      def retranslateUi(self, Widget):
                          _translate = QtCore.QCoreApplication.translate
                          Widget.setWindowTitle(_translate("Widget", "Converter"))
                          self.convert.setText(_translate("Widget", "Convert"))
                      self.convert.clicked.connect(self.convertclick)
                  
                      def convertclick(self):
                          print ('Test')
                  
                  
                  
                  if __name__ == "__main__":
                      import sys
                      app = QtWidgets.QApplication(sys.argv)
                      Widget = QtWidgets.QWidget()
                      ui = Ui_Widget()
                      ui.setupUi(Widget)
                      Widget.show()
                      sys.exit(app.exec_())
                  

                  这是我得到的错误:

                  AttributeError: module 'PyQt5.QtGui' has no attribute 'QWidget'
                  

                  即使我更改了 class Ui_Widget(QtGui.QWidget):class Ui_Widget(QtGui.QtWidgets):我得到 AttributeError: module 'PyQt5.QtGui' has no attribute 'QtWidgets'

                  Even when I change class Ui_Widget(QtGui.QWidget): to class Ui_Widget(QtGui.QtWidgets): I get AttributeError: module 'PyQt5.QtGui' has no attribute 'QtWidgets'

                  有谁知道问题出在哪里?

                  Anyone who knows what the problem may be?

                  干杯.

                  推荐答案

                  你的错误来自这里:

                  Ui_Widget(QtGui.QWidget)
                  

                  它基本上告诉你问题是什么.

                  It basically tells you what the problem is.

                  您似乎在这里混合了一些 QT4 和 QT5,因为您的导入是 QT5 风格,但 QtGui.QWidget 看起来像 QT4 风格.

                  It seems you are mixing some QT4 and QT5 here as your import is in QT5-style, but QtGui.QWidget looks like QT4-style.

                  将行替换为:

                  Ui_Widget(QtWidgets.QWidget)
                  

                  应该根据docs

                  备注:我不知道你到底在做什么,但是当你提到这个时:即使我将 class Ui_Widget(QtGui.QWidget): 更改为 class Ui_Widget(QtGui.QtWidgets): 我得到 AttributeError:模块 'PyQt5.QtGui' 没有属性 'QtWidgets' 没错.您已经导入了 QtWidgets,而不是从 PyQt5.QtGui.只需在那里使用 Ui_Widget(QtWidgets).

                  Remark: I don't know what you are really doing, but when you mention this: Even when I change class Ui_Widget(QtGui.QWidget): to class Ui_Widget(QtGui.QtWidgets): I get AttributeError: module 'PyQt5.QtGui' has no attribute 'QtWidgets' That's correct. You already imported QtWidgets, and not from PyQt5.QtGui. Just use Ui_Widget(QtWidgets) there.

                  简而言之:所有这些错误似乎都与 QT4 和 QT5 之间的模块重构有关.文档应该会有所帮助.

                  In short: all these errors seem to be related to refactoring in regards to the modules between QT4 and QT5. The docs should help.

                  这篇关于AttributeError:模块“PyQt5.QtGui"没有属性“QWidget"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:捕获 QApplication 中引发的异常 下一篇:如何在没有元类冲突的情况下将泛型类型与 PyQ

                  相关文章

                  最新文章

                  <tfoot id='CUVm1'></tfoot>

                    <i id='CUVm1'><tr id='CUVm1'><dt id='CUVm1'><q id='CUVm1'><span id='CUVm1'><b id='CUVm1'><form id='CUVm1'><ins id='CUVm1'></ins><ul id='CUVm1'></ul><sub id='CUVm1'></sub></form><legend id='CUVm1'></legend><bdo id='CUVm1'><pre id='CUVm1'><center id='CUVm1'></center></pre></bdo></b><th id='CUVm1'></th></span></q></dt></tr></i><div id='CUVm1'><tfoot id='CUVm1'></tfoot><dl id='CUVm1'><fieldset id='CUVm1'></fieldset></dl></div>
                    <legend id='CUVm1'><style id='CUVm1'><dir id='CUVm1'><q id='CUVm1'></q></dir></style></legend>
                  1. <small id='CUVm1'></small><noframes id='CUVm1'>

                      <bdo id='CUVm1'></bdo><ul id='CUVm1'></ul>