Hello there,
I am new to Tkinter and want to integrate a matplotlib figure in a Tkinter window, as I am developing a basic GUI for other members of my team.
I was able to indeed have a plot in a Tkinter window, but whenever I hover the mouse over any of the matplotlib toolbar buttons, a Tkinter toplevel window opens. Just when “entering” the button area. If I keep “sweeping” the mouse cursor over the toolbar, several and several windows keep opening.
The buttons do work, by the way.
Follows my sample code:
import tkinter as tk
from tkinter.filedialog import asksaveasfile
from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import (
FigureCanvasTkAgg, # interface between Figure class and Tkinter's Canvas
NavigationToolbar2Tk # built-in toolbar for the figure
)
tk_window = tk.Tk() # initializes Tkinter window
tk_window.title='Tkinter matplotlib integration'
mpl_figure = Figure(figsize=(5,4),dpi=200) # creates matplotlib figure
axs = mpl_figure.add_subplot()
axs.plot([1,2,3,4,5,6],[6,5,4,3,2,1])
tk_canvas = FigureCanvasTkAgg(mpl_figure, tk_window) # creates Tkinter Canvas
tk_canvas.draw()
toolbar = NavigationToolbar2Tk(tk_canvas, tk_window)
toolbar.update()
tk_canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)
tk_window.mainloop()
Any tips are appreciated.
Thanks!