Problem with Matplotlib and the Tk-Backend

thorstenkranz thorstenkranz at
Thu Apr 26 13:39:54 CEST 2007

Hi everyone,

I'm new here and I have a question ( I guess as everybody who is new
here ;-) ),

I'm having some strange problem with Matplotlib, using it in a Tkinter

I create a  Canvas, a figure, subplot and then a toolbar. It works
fine, but only without the toolbar! When I want to add the toolbar, I
get an error

 File "./", line 102, in setupGUI
    self.toolbar = NavigationToolbar2TkAgg( self.canvas, master )
  File "/usr/lib/python2.4/site-packages/matplotlib/backends/", line 537, in __init__
    NavigationToolbar2.__init__(self, canvas)
  File "/usr/lib/python2.4/site-packages/matplotlib/",
line 1107, in __init__
  File "/usr/lib/python2.4/site-packages/matplotlib/backends/", line 577, in _init_toolbar
  File "/usr/lib/python2.4/lib-tk/", line 2378, in __init__
    Widget.__init__(self, master, 'frame', cnf, {}, extra)
  File "/usr/lib/python2.4/lib-tk/", line 1865, in __init__
_tkinter.TclError: bad screen distance "500.0"

Here is the part my code:

        self.canvFrame = Frame(master)
        self.canvFrame.pack(side=TOP, fill=BOTH, expand=1)
        self.canvFrame2 = Frame(self.canvFrame)
        self.canvFrame2.pack(side=LEFT, fill=BOTH, expand=1)
        self.f = Figure(figsize=(5,4), dpi=100)
        self.a = self.f.add_subplot(111)
        self.subplAxis = self.f.get_axes()
        self.canvas = FigureCanvasTkAgg(self.f,
        self.canvas.get_tk_widget().pack(side=TOP, fill=BOTH,
        self.toolbar = NavigationToolbar2TkAgg( self.canvas,
self.canvFrame2 )
        self.canvas._tkcanvas.pack(side=TOP, fill=X, expand=1)

master is a parameter passed to my method, which actually is set to

What did I get wrong? What is the problem? Thanks in advance...


More information about the Python-list mailing list