In Tkinter, Is There A Way To Change The Draw Stack Order Of Overlapping Canvases?
The Problem Using Python's tkinter, I'm trying to create custom buttons and other widgets by extending the Canvas widget. How can I change which custom canvas widgets get drawn on
Solution 1:
Unfortunately you've stumbled on a bug in the tkinter implementation. You can work around this in a couple of ways. You can create a method that does what the tkinter lift
method does, or you can directly call the method in the tkinter Misc
class.
Since you are creating your own class, you can override the lift
method to use either of these methods.
Here's how you do it using the existing function. Be sure to import Misc
from tkinter:
from tkinter import Misc
...
classMyCustomButton(Canvas):
...
deflift(self, aboveThis=None):
Misc.tkraise(self)
Here's how you directly call the underlying tk interpreter:
classMyCustomButton(Canvas):
...
deflift(self, aboveThis=None):
self.tk.call('raise', self._w, aboveThis)
With that, you can raise one button over the other by calling the lift
method:
def click_handler(self,event):
event.widget.lift()
Post a Comment for "In Tkinter, Is There A Way To Change The Draw Stack Order Of Overlapping Canvases?"