From f7926e02f59db97022dd2d08b56eb661902dba5e Mon Sep 17 00:00:00 2001 From: alexanderott Date: Sat, 13 Feb 2021 11:34:09 +0100 Subject: [PATCH] gui testing --- pyqt5_window_test.py | 68 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 pyqt5_window_test.py diff --git a/pyqt5_window_test.py b/pyqt5_window_test.py new file mode 100644 index 0000000..ae29570 --- /dev/null +++ b/pyqt5_window_test.py @@ -0,0 +1,68 @@ +import sys + +from PyQt5.QtWidgets import QApplication, QMainWindow, QMenu, QVBoxLayout, QSizePolicy, QMessageBox, QWidget, QPushButton +from PyQt5.QtGui import QIcon +from PyQt5.QtCore import pyqtSlot + + +from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas +from matplotlib.figure import Figure +import matplotlib.pyplot as plt + +import random + +class App(QMainWindow): + + def __init__(self): + super().__init__() + self.left = 10 + self.top = 10 + self.title = 'PyQt5 matplotlib example - pythonspot.com' + self.width = 640 + self.height = 400 + self.initUI() + + def initUI(self): + self.setWindowTitle(self.title) + self.setGeometry(self.left, self.top, self.width, self.height) + + m = PlotCanvas(self, width=5, height=4) + m.move(0,0) + + button = QPushButton('PyQt5 button', self) + button.setToolTip('This s an example button') + button.move(500,0) + button.resize(140,100) + button.clicked.connect(m.plot) + self.show() + + +class PlotCanvas(FigureCanvas): + + def __init__(self, parent=None, width=5, height=4, dpi=100): + fig = Figure(figsize=(width, height), dpi=dpi) + self.axes = fig.add_subplot(111) + + FigureCanvas.__init__(self, fig) + self.setParent(parent) + + FigureCanvas.setSizePolicy(self, + QSizePolicy.Expanding, + QSizePolicy.Expanding) + FigureCanvas.updateGeometry(self) + self.plot() + + @pyqtSlot() + def plot(self): + data = [random.normalvariate(0,1) for _ in range(200)] + ax = self.axes + ax.clear() + ax.plot(data, 'r-') + ax.set_title('PyQt Matplotlib Example') + self.draw() + + +if __name__ == '__main__': + app = QApplication(sys.argv) + ex = App() + sys.exit(app.exec_()) \ No newline at end of file