python close函数_Matplotlib的close()函数使Tkinter GUI窗口关闭
我試圖用Tkinter制作一個簡單的GUI,它使用Matplotlib生成大量繪圖并將它們保存到硬盤上。在
附件是一個簡單的代碼,但是在保存了所有繪圖之后,Tkinter GUI關閉,腳本停止。我想這個問題可能與plt.關閉(),因為當我刪除plt.關閉(),GUI窗口不再關閉,但毫不奇怪,內存很快就會被填滿,直到整個程序崩潰。在
而不是plt.關閉(),我嘗試使用plt.clf公司(),plt.gcf公司().clear(),圖清除()他們都沒用。它們使GUI窗口保持不變,但會導致內存問題。在
有人知道為什么嗎plt.關閉()關閉Tkinter GUI窗口,如何阻止它?我需要圖形用戶界面(GUI)留下來,并在我處理完對象后,將它們從內存中刪除。在
我使用的是Python3.6.3rc1、windows7、Tkinter 8.6和matplotlib3.0.2。在from tkinter import *
import matplotlib.pyplot as plt
import os
def make_plot():
x = [1, 2, 3, 4, 5]
y = [1, 2, 3, 4, 5]
for j in range(0,20):
fig = plt.figure(num=None, figsize=(20, 10), dpi=200, facecolor='w', edgecolor='w')
plt.plot(x,y)
plt.xlabel("x")
plt.ylabel("y")
out_name = os.getcwd()+ "\\" + str(j)+".png"
print(out_name)
plt.savefig(out_name)
plt.close()
class Application(Frame):
def run_make_plot(self):
make_plot()
def createWidgets(self):
self.button = Button(self)
self.button["text"] = "Plot"
self.button["command"] = self.run_make_plot
self.button.pack()
def __init__(self, master=None):
Frame.__init__(self, master)
self.pack()
self.createWidgets()
root = Tk()
app = Application(master=root)
app.mainloop()
root.destroy()
總結
以上是生活随笔為你收集整理的python close函数_Matplotlib的close()函数使Tkinter GUI窗口关闭的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python3 ocr_OCR识别-py
- 下一篇: runtime 日志权限不够_MySQL