aboutsummaryrefslogtreecommitdiff
path: root/panel.py
blob: ea0c3582d1116f94ba240d9398af4f92c63e91ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import tkinter as tk
from tkinter import *
from tkinter import ttk

import matplotlib.pyplot as plt
from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import (FigureCanvasTkAgg, NavigationToolbar2Tk)

import ue9qol

class Experiment:

    def __init__(self, root):
        self.tic = 0
        self.data = {}
        self.data['tic'] = [] 
        self.data['ch1'] = []
        self.guiSetup(root)
        self.hardware = {}
        self.hardwareSetup()
    
    def hardwareSetup(self):
        self.hardware['LabJack'] = ue9qol.UE9qol()

    def guiSetup(self, root): 

        self.bStart=Button(root,text="START",command=self.hello,font=('Arial','24'))
        self.bStart.pack()

        self.bStop=Button(root,text="STOP",command=exit,font=('Arial','24'))
        self.bStop.pack()

        self.fig=plt.figure()

        self.ax = self.fig.add_subplot(1,1,1)
        self.ax.set_xlim([0,20])
        self.ax.set_ylim([0,20])
        self.ax.plot([i for i in range(10)],[i for i in range(10)])

        self.canvas = FigureCanvasTkAgg(self.fig, master = root)
        self.canvas.draw()

        # placing the canvas on the Tkinter window
        self.canvas.get_tk_widget().pack()
               
        # creating the Matplotlib toolbar
        self.toolbar = NavigationToolbar2Tk(self.canvas, root)
        self.toolbar.update()
                             
        # placing the toolbar on the Tkinter window
        self.canvas.get_tk_widget().pack()

    def hello(self):
        tic = self.tic
        self.data['tic'].append(tic)
        self.data['ch1'].append( self.hardware['LabJack'].getInputCh(1) )
        self.tic = self.tic + 1
        self.ax.plot(self.data['tic'], self.data['ch1'])
        self.canvas.draw()

 
if __name__ == '__main__': 
    root=Tk()

    experiment=Experiment(root) 

    root.mainloop()