Traceback (most recent call last): File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.3.3\plugins\python-ce\helpers\pydev\pydevd.py", line 1483, in _exec pydev_imports.execfile(file, globals, locals) # execute the script File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.3.3\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "D:/01_WorkSpace/04_GitHubPath/sft_ui/Framework/AwControl/test_001.py", line 5, in <module> pyqtgraph.Qt.QtCompat.wrapInstance = pyqtgraph.QtCompat.wrapInstance # 解决 PySide2 的兼容性问题 AttributeError: module 'pyqtgraph' has no attribute 'QtCompat'
时间: 2023-09-02 08:06:36 浏览: 223
BM3D-Denoise-master.rar
这个错误是因为在最新版本的 pyqtgraph 中,没有 `QtCompat` 这个模块。您可以直接去除 `pyqtgraph.Qt.QtCompat.wrapInstance = pyqtgraph.QtCompat.wrapInstance` 这行代码。
下面是经过修改后的示例代码:
```python
import pyqtgraph as pg
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton, QApplication
# 创建一个 GraphicsLayoutWidget
win = pg.GraphicsLayoutWidget()
# 创建一个 QWidget
widget = QWidget()
layout = QVBoxLayout()
button = QPushButton("Click Me!")
layout.addWidget(button)
widget.setLayout(layout)
# 将 QWidget 添加到 GraphicsLayoutWidget 中
win.addWidget(widget)
# 创建应用程序实例
app = QApplication([])
# 显示窗口
win.show()
# 进入事件循环
app.exec_()
```
请确保您已正确安装 PySide2 和 pyqtgraph 库,并注意在运行代码之前将其导入。
阅读全文