I am trying to use tkinter and matplotlib to create an interface to pair with some lab equipment, but right now I am just loading in some old test data. I am trying to add in the NavigationToolbar2Tk navigation bar.
When I run the program the bar pops up properly but every time I click one of the buttons I get the error 'FigureCanvasTkAgg' object has no attribute 'manager'. The funny thing is that all of the buttons except for save will still perform their operations, they just continually spit out the errors. I have tried creating a seperate frame for the navigation box but that hasn't worked.
import tkinter
import matplotlib
matplotlib.use('TkAgg')
from tkinter import Tk
from tkinter import Label as label
from tkinter import Message
from tkinter import Button as button
from tkinter import Canvas as canvas
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib import pyplot as plt
from tkinter import Entry as entry
from matplotlib import style
from matplotlib.backends.backend_tkagg import NavigationToolbar2Tk
import url
dataset = url.open_and_convert_csv("Wednesday_4pm_107_2_Blue.csv")
data = dataset[2:]
x = []
y = []
for row in data:
strain = row[3]
x.append(strain)
stress = row[4]
y.append(stress)
plt.grid(True, which='major', axis='both')
plt.plot(x, y)
figure = plt.gcf()
def tensile_graph():
canv.get_tk_widget().grid(column = 1, row = 1)
def title():
title_text = title_box.get()
title_box.delete(0,len(title_text))
plt.title(title_text)
figure = plt.gcf()
canv = FigureCanvasTkAgg(figure, master=top)
canv.get_tk_widget().grid(column=1, row=1)
def x_ax():
x_ax_text = x_ax_box.get()
x_ax_box.delete(0, len(x_ax_text))
plt.xlabel(x_ax_text)
figure = plt.gcf()
canv = FigureCanvasTkAgg(figure, master=top)
canv.get_tk_widget().grid(column=1, row=1)
def y_ax():
y_ax_text = y_ax_box.get()
y_ax_box.delete(0, len(y_ax_text))
plt.ylabel(y_ax_text)
figure = plt.gcf()
canv = FigureCanvasTkAgg(figure, master=top)
canv.get_tk_widget().grid(column=1, row=1)
top = tkinter.Tk()
top.geometry('1000x600+30+30')
canv = FigureCanvasTkAgg(figure, master=top)
tensile_graph()
options_frame = tkinter.Frame(top)
options_frame.grid(row = 1, column = 0)
title_box = entry(options_frame)
title_box.grid(row = 1, column = 0)
text = title_box.get()
title_button = button(options_frame,text='Apply',command = title)
title_button.grid(row = 1, column = 1)
title_label = label(options_frame,text='Title')
title_label.grid(row = 0, column = 0)
x_axlabel = label(options_frame,text='X Axis Label')
x_axlabel.grid(row = 2, column = 0)
x_ax_box = entry(options_frame)
x_ax_box.grid(row = 3, column = 0)
x_ax_button = button(options_frame, text = 'Apply', command = x_ax)
x_ax_button.grid(row = 3, column = 1)
y_axlabel = label(options_frame,text='Y Axis Label')
y_axlabel.grid(row = 4, column = 0)
y_ax_box = entry(options_frame)
y_ax_box.grid(row = 5, column = 0)
y_ax_button = button(options_frame, text = 'Apply', command = y_ax)
y_ax_button.grid(row = 5, column = 1)
toolbar_frame = tkinter.Frame(top)
toolbar_frame.grid(column = 1, row = 1)
toolbar = NavigationToolbar2Tk(canv,toolbar_frame)
toolbar.update()
canv._tkcanvas.grid(row=1, column=1)
top.mainloop()