I want to make a PolygonSelector from matplotlib to embed in tkinter frame. When i did that, the canvas freeze

54 Views Asked by At

enter image description here

from matplotlib.widgets import AxesWidget
import matplotlib.pyplot as plt
import tkinter as tk
from matplotlib.widgets import PolygonSelector
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg

# from matplotlib.backend_bases import FigureCanvasBase

def callback_function(event):
print(event.x,event.y)

window=tk.Tk()
window.geometry('500x500')
frame1=tk.Frame()
frame1.pack()
figure = plt.figure()
ax=figure.add_subplot(111)
PolygonSelector(ax,callback_function)

# canvas=FigureCanvasBase()

axes_widget=AxesWidget(ax)
FigureCanvasTkAgg(figure, master=frame1).get_tk_widget().pack()
axes_widget.connect_event('button_press_event', callback_function)

window.mainloop()

i have tried the PolygonSelector function to work itself and it works fine. But i want to embed the PolygonSelector widget to my window.

0

There are 0 best solutions below