From: arcege at shore.net (Michael P. Reilly)
Date: Tue, 06 Apr 1999 14:50:13 GMT
Subject: Tkinter bug in Misc.tkraise, Canvas.tkraise
References: <7eaoop$leq$1@news-2.news.gte.net>
Message-ID: <FapO2.24$i06.3597@news.shore.net>
Content-Length: 2470
X-UID: 1468                                                  

John Michelsen <john.michelsen at gte.net> wrote:
: The following got posted in a reply tree by mistake:

: I found a bug in using Tkinter to raise a canvas widget above later
: packed (etc.) widgets.  It seems Tkinter gets confused between the
: Misc.tkraise() method and the Canvas.tkraise(item) methods.
: The following script shows the problem:

: from Tkinter import *

: def raiseCanvas():
:     canvas1.lift()
:     #canvas1.tkraise()
:     #canvas1.widgetlift()

: root = Tk()
: canvas1 = Canvas(root, bg='blue')
: canvas1.place(x=10, y=10, anchor=NW)
: canvas2 = Canvas(root, bg='red')
: canvas2.place(x=20, y=20, anchor=NW)
: raiseButton = Button(root, text='raiseCanvas', command=raiseCanvas)
: raiseButton.pack()
: root.geometry("%dx%d" % (100,100))
: root.mainloop()

: which gives the following error:

: Exception in Tkinter callback
: Traceback (innermost last):
:   File "C:\Program Files\Python\Lib\lib-tk\Tkinter.py", line 764, in
: __call__
:     return apply(self.func, args)
:   File "C:\PROGRA~1\PYTHON\RAISEC~1.PY", line 4, in raiseCanvas
:     canvas1.lift()
:   File "C:\Program Files\Python\Lib\lib-tk\Tkinter.py", line 1287, in
: tkraise
:     self.tk.call((self._w, 'raise') + args)
: TclError: wrong # args: should be ".8249616 raise tagOrId ?aboveThis?"

: I made Tkinter do what I want by adding a method to the Misc
: class and not the Canvas class:

: class Misc...
:     def tkraise(self, aboveThis=None):
:         self.tk.call('raise', self._w, aboveThis)
:     lift = widgetlift = tkraise

: so that widgetlift will call the tkraise in Misc and not the tkraise in
: Canvas.

: I discovered the error in developing a multiple document interface for
: Tkinter
: which can be found on: http://www2.zyvex.com/OpenChem/index.htm
: Dockable toolbars and a tree widget can also be found there.
: They probably don't look very good on unix yet.

It is not a bug with either code, it is a naming problem.  The
Canvas.tkraise is calling the correct code, but it should be called
tag_raise, not tkraise (see the Text widget for naming choice).

Fredrik or Guido, is this something you can change for before 1.5.2 is
released?  (I don't see anything on www.python.org/1.5/ that says when
1.5.2 will be done except "mid March", which has gone by.)

Until then, I would suggest the following fix:

  from Tkinter import Canvas
  Canvas.tag_raise = Canvas.tkraise
  del Canvas.tkraise, Canvas.lift

This should correct the problem.

  -Arcege





