Я создаю графический интерфейс, используя tkinter
, который берет данные в «долларах» и выводит их на график matplotlib. Я понимаю, что для встраивания matplotlib
графика в tkinter
необходимо использовать FigureCanvasTkAgg
и NavigationToolbar2TkAgg
. Этот метод работает, когда я не использовал наследование между родительским классом и дочерним классом.
Когда я пытался внедрить в свою программу несколько страниц, как показано ниже:
Использование кнопок в Tkinter для перехода на разные страницы приложения?
Моя функция относится к классу Page1
, который является подклассом класса Page
. Я начал получать неотзывчивую панель инструментов всякий раз, когда я нажимал кнопки. С TypeError "Label object is not callable
.
Я знаю, что ошибка возникает из-за объявления объекта NavigationToolbar2TkAgg
. Пожалуйста, помогите, я подозреваю, что у меня может быть проблема наследования, так как я создал отдельную рамку для панели инструментов и Figure
canvas.
def plot_data(self,dollars):
"""
This function takes in a list for dollars calculates
the years and converts the lists into numpy arrays and plots
them onto a matplotlib figure embedded into tkinter.
"""
#create a figure object to hold the matplotlib plots
self.figure = Figure(figsize=(5,4), dpi = 100)
#create a subplot first row first column
self.a = self.figure.add_subplot(111)
#update the list of dollars for the plot
self.dollars = np.array(dollars)
self.years = np.arange(0,len(dollars),1)
#plots the numpy arrays into a matplotlib figure 'pyplot'
self.a.plot(self.years,self.dollars,linestyle='none',marker='o')
#holds matplotlib figure in a container to be displayed in tkinter window 'window'
self.canvas = FigureCanvasTkAgg(self.figure, master=self)
#show matplotlib figure on tkinter window
self.canvas.show()
#displays the matplotlib figure on the grid
self.canvas.get_tk_widget().grid(row=10,column=1,columnspan=2,rowspan=20)
#create the toolbar synced with canvas
self.toolbarFrame = tk.Frame(self)
self.toolbarFrame.grid(row=31,column=1)
#creates a navigation toolbar linked to the matplotlib figure with
#the master being the toolbar tk.Frame
self.toolbar = NavigationToolbar2TkAgg(self.canvas,self.toolbarFrame)
#update the plot
self.toolbar.update()