'Draw a line over a window inside a canvas in Tkinter

I am developing some kind of game using python Tkinter and I ran into a problem. I am creating a window of a label inside of my canvas and I want to draw a line over it, however the line is drawn behind the label.

Here is a sample code:

import tkinter as tk

root = tk.Tk()
canv = tk.Canvas(root, width = 200, height = 200)
canv.pack()

text = tk.Label(root, text = "some text")
canv.create_window(100, 100, window = text)
canv.create_line(0, 0, 200, 200, width = 3, fill = "#00ff00")

root.mainloop()

The result is a 200x200 canvas with a label in the middle, and the line is drawn on the canvas and behind the label.
Is there a way to draw the line over the label instead of behind it?

  • Note: it is very important that the label stays a label, the label is the important part not the text


Solution 1:[1]

You cannot draw lines over window objects on a canvas. That is a fundamental limitation of the canvas.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Bryan Oakley