Soda
Soda

Reputation: 89

Arrange rectangle in the background

I have a question. When I create a rectangle in Python Tkinter I want, that this rectangle is created in the background. So that other rectangles are in the foreground.

Example:

rectangle_1 = canvas.create_rectangle(10, 15, 20, 25, fill=black, outline='#b51e00', width=3, dash=(25, 1))
rectangle_2 = canvas.create_rectangle(100, 105, 120, 125, fill=yellow, outline='#b51e00', width=3, dash=(25, 1))
rectangle_3_lowest = canvas.create_rectangle(10, 15, 200, 250, fill=red, outline='#b51e00', width=3, dash=(25, 1))

So now, I'm asking myself, how to arrange the rectangle_3_lowest behind the other two despite it was created at last!

Cheers!

Upvotes: 0

Views: 121

Answers (1)

TheLizzard
TheLizzard

Reputation: 7680

Use canvas.lower(rectangle_3_lowest) like this:

import tkinter as tk

root = tk.Tk()

canvas = tk.Canvas(root)
canvas.pack()

rectangle_1 = canvas.create_rectangle(10, 15, 20, 25, fill="black")
rectangle_2 = canvas.create_rectangle(100, 105, 120, 125, fill="yellow")
rectangle_3_lowest = canvas.create_rectangle(10, 15, 200, 250, fill="red")

canvas.lower(rectangle_3_lowest)

root.mainloop()

Upvotes: 2

Related Questions