1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
canvas = tk.Canvas(root, bg='gray', height=200, width=100)
image_file = tk.PhotoImage(file='tkinter.gif')
image = canvas.create_image(10, 10, anchor='nw', image=image_file)
x0, y0, x1, y1 = 20, 20, 40, 40
# 从坐标(20,20)到(40,40)画一条直线。
line = canvas.create_line(x0, y0, x1, y1)
# 从0度到180度画一个扇形
arc = canvas.create_arc(x0+30, y0+30, x1+30, y1+30, start=0, extent=180)
# 创建一个矩形
rect = canvas.create_rectangle(100, 30, 100+20, 30+20)
# 创建一个填充色为red的圆
oval = canvas.create_oval(x0, y0, x1, y1, fill='red')
canvas.pack()
|