1 #Canvas画布绘制矩形和线以及修改删除操作 2 from tkinter import * 3 4 master = Tk() 5 6 c = Canvas(master,width=400,height=200) 7 c.pack() 8 line1=c.create_line(0,100,400,100,fill='black') 9 line2=c.create_line(200,0,200,200,fill='red',dash=(4,4)) 10 rect1=c.create_rectangle(100,50,300,150,fill='green') 11 12 c.coords(line1,0,50,400,150) 13 c.itemconfig(rect1,fill='red') 14 c.delete(line2) 15 16 Button(master,text='删除全部',command=(lambda x=ALL:c.delete(x))).pack() 17 18 mainloop()
1 #Canvas图案绘制 2 from tkinter import * 3 4 master = Tk() 5 6 c = Canvas(master,width=400,height=200) 7 c.pack() 8 9 line1=c.create_line(0,100,400,100,fill='green',width=5) 10 line2=c.create_line(200,0,200,200,fill='green',width=5) 11 rect1=c.create_rectangle(100,50,300,150,fill='green') 12 rect2=c.create_rectangle(150,75,250,125,fill='yellow') 13 14 c.coords(line1,0,0,400,200) 15 c.coords(line2,400,0,0,200) 16 17 c.create_text(200,100,text='FISHC') 18 19 Button(master,text='删除全部',command=(lambda x=ALL:c.delete(x))).pack() 20 21 mainloop()