gpt4 book ai didi

python - Pyqtgraph - 导入语句的正确顺序?

转载 作者:行者123 更新时间:2023-12-01 01:32:15 26 4
gpt4 key购买 nike

标题中的问题。在下面的导入中,QtCore 和 QtGui 应该从 pyqtgraph 还是 PyQt5 导入?

我的代码工作正常,但看着这个我有不好的代码感觉 - 我不确定 pyqtgraph 如何修补 pyqt5 以及最佳实践是什么。

from PyQt5.QtWidgets import QWidget, QDesktopWidget, QApplication, QLabel, QMainWindow, QHBoxLayout, QVBoxLayout, QSplitter, QFrame,  QSizePolicy
from PyQt5.QtCore import QThread, QObject, QTimer, pyqtSlot, pyqtSignal


from pyqtgraph import PlotWidget
from pyqtgraph.Qt import QtCore, QtGui

最佳答案

从任何一个中,pyqtgraph 都会检测您是否导入了 PyQt5 并将其建立为后端。 Qt.py file负责管理这个逻辑。

例如,如果最初导入了 PyQt5,很容易验证 pyqtgraph 导入的模块与 PyQt5 相同。

from PyQt5 import QtCore as PyQt5QtCore
from PyQt5 import QtGui as PyQt5QtGui
from PyQt5 import QtWidgets as PyQt5QtWidgets

from pyqtgraph.Qt import QtCore as pgQtCore
from pyqtgraph.Qt import QtGui as pgQtGui
from pyqtgraph.Qt import QtWidgets as pgQtWidgets

assert(pgQtCore == PyQt5QtCore)
assert(pgQtGui == PyQt5QtGui)
assert(pgQtWidgets == PyQt5QtWidgets)

关于python - Pyqtgraph - 导入语句的正确顺序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52745817/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com