2015-09-26 89 views
1

以下代码在Python 2.7中运行良好,但在Python 3.3中出现错误消息(以退出代码-1073741819结束)。该错误似乎发生在canvas = FigureCanvasTkAgg(self.f,master = self.root) - 调试不显示任何其他信息。任何建议可能是什么原因以及如何解决它,我们感激。Tkinter上的MatPlotLib在Python 3中以退出代码-1073741819完成

原代码从下面的链接,其中介绍了如何matplotlib与Tkinter的集成来源: http://matplotlib.org/examples/user_interfaces/embedding_in_tk.html

import tkinter as tk 
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg 
from matplotlib.figure import Figure 
import Charts as sp 
class GUI(tk.Frame): 
    def __init__(self, master=None): 
     self.l=[] 
     self.active=False 
     self.root = self.root = tk.Tk() 
     self.root.title('Test') 

     self.x=[]; self.y=[]; self.x = range(0, 100) 
     for each in self.x: 
      self.y.append(2) 
     self.f = Figure(figsize=(5,4), dpi=60); 
     self.a = self.f.add_subplot(111) 

     self.line1, = self.a.plot(self.x, self.y, 'r-') # Returns a tuple of line objects, thus the comma 
     self.a.axis((0,100,0,5)) 
     self.a.set_title('Plot Title') 
     canvas = FigureCanvasTkAgg(self.f, master=self.root) 
     canvas.show() 

if __name__ == '__main__': 
    gui = GUI() 
    gui.root.mainloop() 
+0

你可以启动一个基本的tkinter窗口吗? (例如,尝试'import tkinter; root = tkinter.Tk(); root.mainloop()')我猜你可能在某种程度上为python3安装了破损的Tkinter。 –

+0

tkinter工作正常否则,它只是造成问题的图像CanvasTkAgg。 – Nickpick

+0

如果Tkinter正在工作,那么当您安装matplotlib时会出现问题。你能用'TkAgg'后端显示一个正常的数字吗? (例如'import matplotlib; matplotlib.use(“TkAgg”); import matplotlib.pyplot as plt; plt.subplots(); plt.show()')你是如何安装matplotlib的? –

回答

2

的问题是与蟒蛇。删除并重新安装Matplotlib解决了这个问题。

0

我遇到了同样的问题。更新Anaconda中的matplotlib解决了这个问题。在ipython中,您可以键入
!conda update matplotlib来执行更新。

相关问题