저는 Python에서 매우 새로운 기능을 제공하고 PyQt4 앱을 만들려고합니다. 여기에 PyQtGraph가 포함되어 있습니다. 나는 환상적으로 작동이 PyQtGraph 라이브 플로터있어 : 더 큰 PyQt4 응용 프로그램에 내장 들어PyQt4에서 PyQtGraph로 라이브 플로팅
from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg
import random
app = QtGui.QApplication([])
p = pg.plot()
curve = p.plot()
data = [0]
def updater():
data.append(random.random())
curve.setData(data) #xdata is not necessary
timer = QtCore.QTimer()
timer.timeout.connect(updater)
timer.start(0)
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
을, 나는 pyqtgraph.PlotWidget() 포함을위한 레이아웃이 필요합니다. 그 문제에 관해서는 MainWindow에 centralWidget을 설정했습니다. 그 이전의 코드가하는 것처럼 플롯 시작해야, 버튼을 만들,하지만 난 플로터 기능을 통해 업데이트 프로그램 함수를 호출 할 때 그냥 아무 반응이 없습니다 :
import sys
from PyQt4 import QtCore, QtGui
import pyqtgraph as pg
import random
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.central_widget = QtGui.QStackedWidget()
self.setCentralWidget(self.central_widget)
login_widget = LoginWidget(self)#to say where the button is
login_widget.button.clicked.connect(self.plotter)
self.central_widget.addWidget(login_widget)
def plotter(self):
self.data =[0]
timer = QtCore.QTimer()
timer.timeout.connect(self.updater)
timer.start(0)
def updater(self):
self.data.append(random.random())
plot.setData(self.data)
class LoginWidget(QtGui.QWidget):
def __init__(self, parent=None):
global plot
super(LoginWidget, self).__init__(parent)
layout = QtGui.QHBoxLayout()
self.button = QtGui.QPushButton('Start Plotting')
layout.addWidget(self.button)
plot = pg.PlotWidget()
layout.addWidget(plot)
self.setLayout(layout)
if __name__ == '__main__':
app = QtGui.QApplication([])
window = MainWindow()
window.show()
app.exec_()
아무것도 내가 스레드해야하기 때문에 일이 없다?
감사합니다. @ImportanceOfBeingErnest, 저는 실제로 변수 범위를 이해하고 실행하려고 노력하고 있지만 시간이 좀 걸립니다. 운이 좋은 너희들은 열정적 인 프로그래머 :-) 또한 설명서에서 pg.PlotWidget() 올바른 사용을 찾지 못했습니다 ..... 다시 한번 감사드립니다! – Ivy
이 문제가 해결 된 경우 [수락] (http://meta.stackexchange.com/a/5235)을 고려하십시오. 적절하지 않은 경우 질문을 수정하십시오. – ImportanceOfBeingErnest