Я использую matplotlib и tkinter в python 2.7.12.При использовании кнопки для запуска команды, которая создает фигуру matplotlib, сохраняет фигуру, а затем использует plt.close(fig)
, чтобы закрыть фигуру, окно tkinter также закрывается (что мне не нужно).Если я удаляю строку plt.close(fig)
, окно tkinter остается открытым, но закрытие окна tkinter не завершает процесс.Как правильно закрыть фигуру matplotlib, не закрывая окно tkinter?
Пример кода:
import matplotlib.pyplot as plt
import tkinter as tk
def command():
fig, ax = plt.subplots(1, 1)
x = range(0, 10, 2)
y = x
ax.plot(x, y)
fig.savefig('test.png')
plt.close(fig) # this line makes the tkinter window close after the command runs
root = tk.Tk()
button = tk.Button(root, text='click me', command=command)
button.grid(row=0, column=0)
root.mainloop()