Problem with Matplotlib and the Tk-Backend

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • thorstenkranz

    #1

    Problem with Matplotlib and the Tk-Backend

    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
    application.

    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 "./tkViewer.py", line 102, in setupGUI
    self.toolbar = NavigationToolb ar2TkAgg( self.canvas, master )
    File "/usr/lib/python2.4/site-packages/matplotlib/backends/
    backend_tkagg.p y", line 537, in __init__
    NavigationToolb ar2.__init__(se lf, canvas)
    File "/usr/lib/python2.4/site-packages/matplotlib/backend_bases.p y",
    line 1107, in __init__
    self._init_tool bar()
    File "/usr/lib/python2.4/site-packages/matplotlib/backends/
    backend_tkagg.p y", line 577, in _init_toolbar
    borderwidth=2)
    File "/usr/lib/python2.4/lib-tk/Tkinter.py", line 2378, in __init__
    Widget.__init__ (self, master, 'frame', cnf, {}, extra)
    File "/usr/lib/python2.4/lib-tk/Tkinter.py", line 1865, in __init__
    self.tk.call(
    _tkinter.TclErr or: 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.canv Frame)
    self.canvFrame2 .pack(side=LEFT , fill=BOTH, expand=1)
    self.f = Figure(figsize= (5,4), dpi=100)
    self.a = self.f.add_subp lot(111)
    self.subplAxis = self.f.get_axes ()
    self.canvas = FigureCanvasTkA gg(self.f,
    master=self.can vFrame2)
    self.canvas.sho w()
    self.canvas.get _tk_widget().pa ck(side=TOP, fill=BOTH,
    expand=1)
    self.toolbar = NavigationToolb ar2TkAgg( self.canvas,
    self.canvFrame2 )
    self.toolbar.up date()
    self.canvas._tk canvas.pack(sid e=TOP, fill=X, expand=1)


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

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

    Thorsten

  • James Stroud

    #2
    Re: Problem with Matplotlib and the Tk-Backend

    thorstenkranz wrote:
    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
    application.
    >
    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 "./tkViewer.py", line 102, in setupGUI
    self.toolbar = NavigationToolb ar2TkAgg( self.canvas, master )
    File "/usr/lib/python2.4/site-packages/matplotlib/backends/
    backend_tkagg.p y", line 537, in __init__
    NavigationToolb ar2.__init__(se lf, canvas)
    File "/usr/lib/python2.4/site-packages/matplotlib/backend_bases.p y",
    line 1107, in __init__
    self._init_tool bar()
    File "/usr/lib/python2.4/site-packages/matplotlib/backends/
    backend_tkagg.p y", line 577, in _init_toolbar
    borderwidth=2)
    File "/usr/lib/python2.4/lib-tk/Tkinter.py", line 2378, in __init__
    Widget.__init__ (self, master, 'frame', cnf, {}, extra)
    File "/usr/lib/python2.4/lib-tk/Tkinter.py", line 1865, in __init__
    self.tk.call(
    _tkinter.TclErr or: 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.canv Frame)
    self.canvFrame2 .pack(side=LEFT , fill=BOTH, expand=1)
    self.f = Figure(figsize= (5,4), dpi=100)
    self.a = self.f.add_subp lot(111)
    self.subplAxis = self.f.get_axes ()
    self.canvas = FigureCanvasTkA gg(self.f,
    master=self.can vFrame2)
    self.canvas.sho w()
    self.canvas.get _tk_widget().pa ck(side=TOP, fill=BOTH,
    expand=1)
    self.toolbar = NavigationToolb ar2TkAgg( self.canvas,
    self.canvFrame2 )
    self.toolbar.up date()
    self.canvas._tk canvas.pack(sid e=TOP, fill=X, expand=1)
    >
    >
    master is a parameter passed to my method, which actually is set to
    Tk()
    >
    What did I get wrong? What is the problem? Thanks in advance...
    >
    Thorsten
    >
    Just prior to "self.toolb ar = ...", try :

    master.winfo_to plevel().update _idletasks()

    James

    Comment

    Working...