#在画布上添加各种几何图形
from tkinter import *
root=Tk()
#设置主窗口区的背景顔色以区别画布区的顔色
root.config(bg='#8DB6cD')
root.title("基于tk的canvas几何图形")
root.geometry('500x400')
#画布设置为白色
canvas=Canvas(root,width=400,height=400,bg='white')
#设置基准坐标
x0,y0,x1,y1=10,10,80,80
#绘制扇形
arc=canvas.create_arc(x0,y0,x1,y1,start=0,extent=270,fill='grey',outline='blue',width='2')
#绘制圆形
oval=canvas.create_oval(x0+150,y0,x1+150,y1,fill='brown',outline='blue',width=2)
#矩形
rect=canvas.create_rectangle(x0,y0+100,x1,y1+100,fill='red',outline='green')
#三角
trigon=canvas.create_polygon(80,80,150,80,200,200,outline='',fill='green')
poly_points=[(0,280),(140,200),(140,240),(270,240),(270,320),(140,320),(140,360)]
polygon=canvas.create_polygon(poly_points,fill='#BF3EFF')
canvas.pack()
root.mainloop()