[Tkinter-discuss] Need help using Tkinter Widget lift() and lower() methods with Place geometry Manager

Michael O'Donnell michael.odonnell at uam.es
Sat Mar 15 08:55:04 CET 2014


Dear GKalman,

  According to the documentation, lift and lower affect the
toplevel that contains the canvas, they do not change
stacking order of widgets within a toplevel.

Maybe the better alternative is to call
a place_forget() on the lower canvas and
then place it again, which should put it
above.

I have never used place() and am not
sure of its abilities to do what you want.

Another possibility is to use a Canvas
instead of your enclosing frame, and
then use creatr_window to place
your canvases within the enclosing canvas,
and use canvas methods: move, tag_raise
and tag_lower raise and lower your
canvases relative to each other.

Just a suggestion,

Mick

On 15 March 2014 02:20, GKalman <kalman_g at verizon.net> wrote:
> """
> I tried a simple case:
> Frame with two Canvas widgets. I drag (i.e. move) Canvas #1. When it
> overlaps with Canvas #2 neither the lift() nor the lower() methods work.
> Why?
> """
> from Tkinter import *
>
> class myObject():
>     #--------------------------------
>     def __init__(self,root):
>         self.root = root
>
>         #place a Frame on the root:
>         self.f = Frame(self.root, bg="yellow", width=600, height=400)
>         self.f.pack()
>
>         #place a Canvas on the Frame:
>         self.c =Canvas(self.f, bg="cyan",width=100,height=50)
>         #NW-vtx of Canvas:
>         self.xNW=10
>         self.yNW=10
>         self.c.place(x=self.xNW,y=self.yNW)
>
>         ##event-generators:
>         self.c.bind('<ButtonPress-1>', self.startMoveWindow)
>         self.c.bind('<B1-Motion>', self.MoveWindow)
>
>         self.c2=Canvas(self.f,bg="red",width=100,height=100)
>         self.c2.place(x=300,y=200)
>         self.c2.lower(self.c)
>
>     #-----------------------------------------------
>     def startMoveWindow(self, event):
>         ## at start: record current root coordinates
>         self.xo, self.yo = event.x_root, event.y_root
>
>     #--------------------------------------
>     def MoveWindow(self, event):
>         self.root.update_idletasks()
>
>         ## use root coordinates for offset of Widget (canvas) coordinates
>         self.xNW += event.x_root - self.xo
>         self.yNW+= event.y_root - self.yo
>         ## update coordinates
>         self.xo, self.yo= event.x_root, event.y_root
>
>         ## Move & redraw Widget (canvas)
>         self.c.place_configure(x=self.xNW, y=self.yNW)
>
> #==================================
> root=Tk()
> x = myObject(root)
> root.mainloop()
>
>
>
> --
> View this message in context: http://python.6.x6.nabble.com/Need-help-using-Tkinter-Widget-lift-and-lower-methods-with-Place-geometry-Manager-tp5050511.html
> Sent from the Python - tkinter-discuss mailing list archive at Nabble.com.
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> https://mail.python.org/mailman/listinfo/tkinter-discuss


More information about the Tkinter-discuss mailing list