fernando
fernando

Reputation: 99

frame on canvas overlapping a line created in canvas

I need to create a frame in a canvas in order to delete a decent amount of widget that the user can place in the canvas. It places in the frame instead so I can delete them with canvas.delete("all"). I need also some lines, as Frame doesn't accept lines, I need to create it directly in the canvas below. The problem is that the Frame overlaps the line. I tried the method canvas.lift() and tag.raise(), but they don't work. Any idea how to fix it?

from tkinter import *

root = Tk()
root.geometry('1560x750')

canvas_right=Canvas(root)
canvas_right.config(width=1000, height=1560, bg='light grey')
canvas_right.grid(row=1,column=3, rowspan=1550,ipadx=1300,ipady=750,sticky=NW)

frame = Frame(canvas_right, bg='light blue')
main_frame = canvas_right.create_window(500, 780, height=1700, width=760, window=frame)

line1 = canvas_right.create_line(100,100,3000,1000)
canvas_right.lift(line1)

root.mainloop()

enter image description here

Upvotes: 0

Views: 126

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 386285

Widgets placed in a canvas will always be above other graphical items like lines and circles. There is no way to work around that limitation.

From the canonical tcl/tk documentation:

Note: due to restrictions in the ways that windows are managed, it is not possible to draw other graphical items (such as lines and images) on top of window items. A window item always obscures any graphics that overlap it, regardless of their order in the display list. Also note that window items, unlike other canvas items, are not clipped for display by their containing canvas's border, and are instead clipped by the parent widget of the window specified by the window option; when the parent widget is the canvas, this means that the window item can overlap the canvas's border.

Upvotes: 2

Related Questions