- Canvas画布基础版本
# Canvas画布1,最基础版
import tkinter as tk
window = tk.Tk()
window.title('canvas 画布')
window.geometry('1000x500')
canvas = tk.Canvas(window,bg = 'white',height = 600,width = 400)
image1 = tk.PhotoImage(file = 'F:/Python/a1.png') #打开图片,但好像只能打开png格式的。
image = canvas.create_image(10,10,anchor = 'nw',image = image1) #将图片的西北角(左上角)固定在(10,10)这个位置上。
canvas.pack()
window.mainloop()
2 . 画布——增加形状
import tkinter as tk
window = tk.Tk()
window.title('Scale尺度')
window.geometry('1000x500')
canvas = tk.Canvas(window,bg = 'white',height = 600,width = 400)
canvas.pack()
# 导入图片
image1 = tk.PhotoImage(file = 'F:/Python/a1.png')
image = canvas.create_image(10,10,anchor = 'nw',image = image1)
# 导入其它形状
x0,y0,x1,y1 = 250,250,280,280
line = canvas.create_line(x0,y0,x1,y1) #直线
oval = canvas.create_oval(x0,y0,x1,y1,fill = 'red') #圆形
arc = canvas.create_arc(x0+30,y0+30,x1+30,y1+30,start = 0,extent = 120) #扇形,起止角度
rect = canvas.create_rectangle(20,20,200,200) #矩形
window.mainloop()