Set Tkinter Canvas Background Color

The bgcolor() function is used to set the background color of an HTML page, and its usage is as follows:

from tkinter import *

root = Tk()

# 创建一个Canvas对象
canvas = Canvas(root, bg="white")
canvas.pack()

# 设置Canvas的背景颜色为白色
canvas.create_rectangle(50, 50, 150, 150, fill="blue")

root.mainloop()

In the example above, we created a Canvas object and set its background color to white. Next, we used the create_rectangle() method to draw a blue rectangle on the Canvas. This example showcases how to use the bgcolor() function.

bannerAds