1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| canvas=Canvas(win,width=200,height=200,bg="#EFEFA3").pack() """ 属性: bd:边框宽 默认2px bg confine:如果默认True,画布不能滚动到可滑动区域外 cursor height width highlightcolor:高亮边框颜色 relief scrollregion:tuple(w,n,e,s) 左上右下可滑动最大区域 xscrollincrement:水平/垂直滚动时,请求滚动的数量值 yscrollincrement xscrollcommand:绑定水平/垂直滚动条 yscrollcommand """ line1=canvas.create_line(x1,y1,x2,y2,...,xn,yn,...) """ arrow:是否添加箭头,默认无,值:FIRST起始端右箭头 LAST末端右箭头 BOTH两端都有箭头 arrowshap:(d1,d2,d3) 箭头形状,三角形底、斜边、高 capstyle:终点样式,默认BUTT,其他:PROJECTING ROUND dash:(x1,x2) 设置为虚线,且值为x1px实线与x2px空白交替出现 dashoffset:同dash x1,x2交换 fill:颜色 joinstyle:线条焦点颜色 ROUND BEVEL MITER stipple:绘制位图线条 width:线宽 """ rect=canvas.create_rectangle(x1,y1,x2,y2,...) canvas.move(rect,x1,x2) """ 属性: dash dashoffset stipple width outline:轮廓颜色 fill:填充颜色 """ cir1=canvas.create_oval(x1,y2,x2,y2,...) arc1=canvas.create_arc(x1,y1,x2,y2,extend=120,style=ARC,...) arc2=canvas.create_arc(x1,y1,x2,y2,extent=120,start=startanfle,width=2,style=PIESLICE) poly1=canvas.create_polygon(x1,y1,x2,y2,...,...) text=canvas.create_text(x,y,text=str,...) """ 常用属性:font fill justify等 """ canvas.delete("all") bird1=PhotoImage(file="*.png") bird=canvas.create_image(x,y,image=bird1,...)
def draw(event): canvas.coords(bird,event.x,event.y) canvas.bind("<B1-Motion>",draw) canvas.move(ID,x,y)
|