我想創建一個與matplotlib.Everything python tkinter的條形圖工作正常,除了當我關閉tkinter(控制檯)窗口,它給我這個消息。Python關閉控制檯Matplotlib運行時錯誤
我已經關閉我的控制檯,所以我不知道哪個處理它指的是「仍在運行」之前關閉我的Tkinter窗口。當我選擇殺它,它給我這個錯誤消息:
,只當我有我的matplotlib代碼嵌入發生。當我從我的腳本中刪除我的matplotlib代碼時,它不再給我這個消息並且工作正常。我的代碼如下:
進口我的腳本
import Tkinter as tk
import matplotlib
matplotlib.use('TkAgg')
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
from matplotlib.backend_bases import key_press_handler
from matplotlib.figure import Figure
from datetime import datetime
Matplotlib相關的代碼
frame=tk.Frame(parent,width=900,height=500,bg='lightgreen',relief='groove',bd=1)
frame.place(x=10,y=10)
fig=plt.figure()
ax=fig.add_subplot(211)
canvas = FigureCanvasTkAgg(fig, master=frame)
canvas.show()
canvas.get_tk_widget().pack(side='top', fill='both', expand=1)
canvas._tkcanvas.pack(side='top', fill='both', expand=1)
toolbar = NavigationToolbar2TkAgg(canvas,frame)
toolbar.update()
canvas._tkcanvas.pack(side='top', fill='both', expand=1)
def on_key_event(event):
key_press_handler(event, canvas, toolbar)
什麼原因造成的問題?
我使用的Windows8(64位)和Python 2.7.4,matplotlib 1.2.0(64位)爲Python 2.7