What is the usage of fillcolor in Python?

In Python, fillcolor is a method in Tkinter Canvas used to set the fill color of graphic objects.

The fillcolor method requires a color value to be passed as a parameter, which can be a predefined color name (such as ‘red’, ‘blue’, ‘green’, etc.) or a color code represented in hexadecimal format (for example, ‘#FF0000’ represents red).

Below is a basic example of how to use fillcolor:

from tkinter import *

root = Tk()
canvas = Canvas(root)

# 在画布上绘制一个矩形,并设置填充颜色为红色
rectangle = canvas.create_rectangle(50, 50, 150, 150)
canvas.itemconfig(rectangle, fill='red')

canvas.pack()
root.mainloop()

In the above example, we created a rectangle object and filled it with the color red using the fillcolor method. You can choose a different color to fill the shape object according to your needs.

bannerAds