Answer
Here is an example of how you can draw a color filled rectangle on a Tkinter canvas:
import tkinter as tk
root = tk.Tk()
canvas = tk.Canvas(root, bg="white", height=200, width=200)
canvas.pack()
x1 = 70 - 50
y1 = 70 - 50
x2 = 70 + 50
y2 = 70 + 50
canvas.create_rectangle(x1, y1, x2, y2, fill="red")
root.mainloop()
Work Step by Step
In this code, we first create the main window of the Tkinter application using the Tk() method and assign it to the variable root. Next, we create a canvas using the Canvas constructor, specifying the parent window as root and setting the background color to "white", the height to 200, and the width to 200. Then, we use the pack() method to display the canvas on the screen.
Next, we calculate the coordinates for the four corners of the rectangle centered at (70, 70) with a width of 100 and a height of 100. We do this by subtracting 50 from both x and y to get the top-left corner, and adding 50 to both x and y to get the bottom-right corner.
Finally, we use the create_rectangle method of the canvas to draw a rectangle with the top-left corner at (x1, y1) and the bottom-right corner at (x2, y2), and set the fill color to "red". The rectangle will be drawn with the specified coordinates and fill color.