import tkinter as tk
# 创建窗口
window = tk.Tk()
window.title("画图程序")
window.geometry("400x400")
# 绘制矩形
def draw_rectangle():
canvas.create_rectangle(50, 50, 150, 100, fill=None, outline="red")
# 绘制椭圆
def draw_oval():
canvas.create_oval(50, 150, 150, 200, fill=None, outline="green")
# 绘制圆弧
def draw_arc():
canvas.create_arc(50, 250, 150, 300, start=0, extent=120, style=tk.ARC)
# 绘制多边形
def draw_polygon():
points = [200, 100, 250, 150, 200, 200, 150, 150]
canvas.create_polygon(points, fill=None, outline="blue")
# 绘制直线
def draw_line():
canvas.create_line(200, 250, 300, 250, fill="purple", width=2)
# 绘制圆
def draw_circle():
canvas.create_oval(250, 50, 300, 100, fill=None, outline="orange")
# 绘制正方形
def draw_square():
canvas.create_rectangle(250, 150, 300, 200, fill=None, outline="gray")
# 绘制长方形
def draw_rectangle2():
canvas.create_rectangle(250, 250, 300, 300, fill=None, outline="brown")
# 创建按钮
rectangle_button = tk.Button(window, text="矩形", command=draw_rectangle)
rectangle_button.pack()
oval_button = tk.Button(window, text="椭圆", command=draw_oval)
oval_button.pack()
arc_button = tk.Button(window, text="圆弧", command=draw_arc)
arc_button.pack()
polygon_button = tk.Button(window, text="多边形", command=draw_polygon)
polygon_button.pack()
line_button = tk.Button(window, text="直线", command=draw_line)
line_button.pack()
circle_button = tk.Button(window, text="圆", command=draw_circle)
circle_button.pack()
square_button = tk.Button(window, text="正方形", command=draw_square)
square_button.pack()
rectangle2_button = tk.Button(window, text="长方形", command=draw_rectangle2)
rectangle2_button.pack()
# 创建画布
canvas = tk.Canvas(window, width=300, height=300)
canvas.pack()
window.mainloop()