1

The following code works well in Python 2.7, but gives an error message in Python 3.3 (finished with exit code -1073741819). The error seems to occur in canvas = FigureCanvasTkAgg(self.f, master=self.root) - debugging does not show any additional information. Any suggestions what could be the cause and how to fix it are appreciated.

The original code originates from the below link, which describes how to integrate matplotlib with 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()
6
  • Can you launch a basic tkinter window? (e.g. try import tkinter; root = tkinter.Tk(); root.mainloop()) I'm guessing that you might somehow have a broken Tkinter install for python3. Commented Sep 26, 2015 at 16:56
  • tkinter is working fine otherwise, it's just FigureCanvasTkAgg that is causing problems. Commented Sep 26, 2015 at 17:51
  • If Tkinter is working, then something went wrong when you installed matplotlib. Can you display a normal figure with the TkAgg backend? (e.g. import matplotlib; matplotlib.use("TkAgg"); import matplotlib.pyplot as plt; plt.subplots(); plt.show()) How did you install matplotlib? Commented Sep 26, 2015 at 17:56
  • Yes I can display normal plots as long as they are not in combination with tkinter. I'm using Anaconda3, so everything was pre-installed. That worked very well with version 2.7 and everything else seems to be ok with version 3. Correction: I just run your example and while the window opens, Python crashes. "python.exe has stopped working" and the plot window is "not responding" Commented Sep 26, 2015 at 18:03
  • WIthout TkAgg it's working fine, but when I use it then python.exe crashes. Commented Sep 26, 2015 at 18:05

2 Answers 2

2

The problem was with Anaconda. Removing and reinstalling Matplotlib resolved the problem.

Sign up to request clarification or add additional context in comments.

Comments

0

I ran into the same issue. Update matplotlib in Anaconda solved the issue. In ipython, you can type
!conda update matplotlib to do the update.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.