Luego de cerrar la ventana que contiene la imagen no finaliza la ejecucion del programa sino que debo forzar a interrumpir la ejecucion.
import tkinter
import tkinter as tk
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
# Crear ventana de tkinter
ventana = tk.Tk()
ventana.geometry('400x400')
# Crear figura de Matplotlib
fig, ax = plt.subplots()
ax.plot([1, 2, 3, 4, 5], [1, 4, 2, 3, 5])
marco = tkinter.Frame(ventana)
marco.pack()
# Crear objeto FigureCanvasTkAgg
canvas = FigureCanvasTkAgg(fig, master=marco)
canvas.draw()
# Agregar objeto FigureCanvasTkAgg a la ventana de tkinter
canvas.get_tk_widget().pack()
# Ejecutar bucle principal de tkinter
ventana.mainloop()
Me indica que hay un error en el mainloop principal del programa.
C:\Users\afgb9\AppData\Local\Programs\Python\Python311\python.exe D:\Dropbox\AGPROGRAM\Python\prueba2.py
Traceback (most recent call last):
File "D:\Dropbox\AGPROGRAM\Python\prueba2.py", line 24, in <module>
ventana.mainloop()
File "C:\Users\afgb9\AppData\Local\Programs\Python\Python311\Lib\tkinter\__init__.py", line 1485, in mainloop
self.tk.mainloop(n)
KeyboardInterrupt
Process finished with exit code -1073741510 (0xC000013A: interrupted by Ctrl+C)
Gracias