pyqtgraph-导入语句的正确顺序?

时间:2018-10-10 17:31:29

标签: python pyqt pyqt5 pyqtgraph

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

我的代码工作正常,但是看这个代码我感觉很不好-我不确定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

1 个答案:

答案 0 :(得分:2)

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)