I want to have two live plots on two pages in a tkinter GUI with buttons to stop the live updating. So far I've managed to create one live plot in my first page. However, I have problems with creating threads inside other functions.
api = csb.SeaBreezeAPI()
devices = list_devices() #to get the serial number of the device
spec = sb.Spectrometer.from_serial_number("FLMS15412")
xs = spec.wavelengths()
ys = spec.intensities()
fig1 = Figure(figsize=(10,6),tight_layout=True)
ax1 = fig1.add_subplot(111)
root = tk.Tk()
root.configure(background = 'light blue')
root.geometry("1400x800")
canvas1=FigureCanvasTkAgg(fig1,master=root)
canvas1.get_tk_widget().place(x=5,y=55)
cond = False
def starts():
root.after(1,starts)
cond = False
def plot_data():
if (cond == True):
ax1.cla()
ax1.plot(spec.wavelengths(),spec.intensities
(correct_dark_counts=True),'w',linewidth=1.0)
ax1.set_xlabel('Wavelength (nm)')
ax1.set_ylabel('Intensity (a.u.)')
ax1.set_xlim(200,1000)
ax1.set_ylim(0,60000)
ax1.set_facecolor('#1B1B2A')
ax1.grid(color='w',linestyle='--',linewidth=0.2)
canvas1.draw()
root.after(1,plot_data)
def plot_start():
global cond
cond = True
def plot_stop():
global cond
cond = False
root.update()
startplot = tk.Button(root, text = "Start", font = ('calibri', 12), command = lambda: plot_start())
startplot.place(x=5,y=25)
root.update()
stopplot = tk.Button(root, text = "Stop", font = ('calibri', 12), command = lambda: plot_stop())
stopplot.place(x=65,y=25)
root.update()
start = tk.Button(root, text = "Stage", font = ('calibri', 12),
command=threading.Thread(target=plot_data).start())
start.place(x=125,y=25)
threading.Thread(target=plot_data).start()
root.after(1,plot_data)
root.mainloop()
This is a minimal code for the live plot in a single page. I want to create another page with another live plot. How can I do that with tkinter. Any help would be appreciated.