填充 Tkinter 画布。填充由不同基本形状和图像组成的图形的最简单方法是什么?

问题描述 投票:0回答:1

我正在用几个原始形状创建一个图形,对我来说同时绘制它们的最简单方法是什么?

这就是我创建图形的方式:

from tkinter import *
root=Tk()
c=Canvas(root,width=700,height=500,bg='blue',cursor="pencil")
c.create_arc(300,200,250,175,outline='white',style=ARC,start=0,extent=180)#1
c.create_arc(250,200,200,175,outline='white',style=ARC,start=0,extent=180)#2
c.create_arc(200,200,150,175,outline='white',style=ARC,start=0,extent=180)#3
c.create_arc(150,200,100,175,outline='white',style=ARC,start=0,extent=180)#4
c.create_arc(100,100,300,270,outline='white',style=ARC,start=0,extent=180)#umbrella
c.create_line(200,185,200,300,fill='white')
c.create_arc(200,325,250,275,outline='white',style=ARC,start=180,extent=180)
c.pack()
root.mainloop()

我试图找到 FloodFill 命令的类似物(来自 Pascal),但我找不到

我将非常感谢您的帮助

python tkinter tkinter-canvas
1个回答
0
投票

您可以使用

tags
将画布对象分组在一起。 这可用于集体更改填充、轮廓和其他属性以及移动和缩放的组控制。

注意: 画布

line
仅使用填充而不使用轮廓,因此对于单行尝试使用多边形。

from tkinter import *

root=Tk()

c=Canvas(root,width=700,height=500,bg='blue',cursor="pencil")
c.pack()

# polygon instead of line
c.create_polygon(200,185,200,300, tags="hue")
c.create_arc(200,325,250,275, style=ARC, tags="hue", start=180, extent=180)
c.create_arc(300,200,250,175, style=ARC, tags = "hue", start=0, extent=180)#1
c.create_arc(250,200,200,175, style=ARC, tags = "hue", start=0, extent=180)#2
c.create_arc(200,200,150,175, style=ARC, tags = "hue", start=0, extent=180)#3
c.create_arc(150,200,100,175, style=ARC, tags = "hue", start=0, extent=180)#4
c.create_arc(100,100,300,270, style=ARC, tags = "hue", start=0, extent=180)#umbrella

# Color and change properties of all objects in one statement using tags
c.itemconfig("hue", fill="orange", outline="yellow", width=4)

root.mainloop()
© www.soinside.com 2019 - 2024. All rights reserved.