【发布时间】:2025-12-15 22:45:02
【问题描述】:
我只是从 pyqtgraph 开始。我有一个 graphicsView 小部件,我根据文档使用 QT 设计器进行了推广。我想尝试一个情节,看看它是否有效。当我尝试pg.plot(x,y) 时,程序在单独的窗口中而不是在 graphicsView 小部件中创建了一个绘图。我正在使用 Windows 10、PyQt4 和 Python 2.7。我做错了什么?
from PyQt4 import QtGui
from PyQt4 import QtCore
import ui_test #Gui File
import sys
import pyqtgraph as pg
class Gui(QtGui.QMainWindow, ui_test.Ui_MainWindow):
def __init__(self):
super(self.__class__, self).__init__()
self.setupUi(self) # This is defined in ui_pumptest.py file automatically
self.plot()
def plot(self):
vb = pg.ViewBox()
self.graphicsView.setCentralItem(vb)
def main():
app = QtGui.QApplication(sys.argv) # A new instance of QApplication
form = Gui() # We set the form to be our ExampleApp (design)
form.show() # Show the form
app.exec_() # and execute the. app
if __name__ == '__main__': # if we're running file directly and not importing it
main() # run the main function
【问题讨论】: