墨玦 发表于 2024-8-14 15:58:19

tkinter中Canvas——create_polygon画五角星,颜色填充问题

from tkinter import *
import math as m

root = Tk()

w = Canvas(root,width=200,height=100)
w.pack()

center_x = 100
center_y = 50
r = 50

points = [
    center_x - int(r * m.sin(2 * m.pi / 5)),center_y - int(r * m.cos(2 * m.pi / 5)),
    center_x + int(r * m.sin(2 * m.pi / 5)),center_y - int(r * m.cos(2 * m.pi / 5)),
    center_x - int(r * m.sin(m.pi / 5)),center_y + int(r * m.cos(m.pi / 5)),
    center_x,center_y - r,
    center_x + int(r * m.sin(2 * m.pi / 10)),center_y + int(r * m.cos(m.pi / 5))
]

w.create_polygon(points,outline="green",fill="yellow")

mainloop()
为什么上面的代码画出来的五角星,中心区域没有被填充成黄色,要怎么改进?
页: [1]
查看完整版本: tkinter中Canvas——create_polygon画五角星,颜色填充问题