canvas_height))) # 调整图片大小以适应画布 self.canvas.create_image(0, 0, anchor=tk.NW, image=self.photo) self.root.mainloop() def on_mouse_press(self, event): self.start_x = event.x self.start_y = event.y def on_mouse_drag(self, event): self.canvas.delete("crop_rectangle") ...
w = Canvas(root, width=200, height=100,bg="yellow") w.pack() # 使用PhotoImage方法加载图片 photo = PhotoImage(file="test.png") # 显示图片 前面两个数字表示图片显示位置 锚点默认图片中心 anchor参数可以更改锚点 w.create_image(100,50,image=photo) # w.create_image(100,0,anchor="n",image=...
canvas = Canvas(root, width =500, height =500) canvas.pack img = ImageTk.PhotoImage(Image.open("www.linuxmi.com.png")) canvas.create_image(0,0, anchor=NW, image=img) root.mainloop 图像类具有属性 "open" ,它将打开不太直接支持的图像格式,并且与"ImageTk.PhotoImage"一起,我们可以返回图像对...
tk.geometry("+%s+%s"%(_x, _y))defupdate(flags):globalind## print(ind)ifflags:try: canvas.delete('imageC')if(ind == framenum-1):#ind =0 frame=frames[ind] image1= canvas.create_image((80,220),image=frame,anchor='w',tags='imageC') ind+= 1except:passif__name__=='__main_...
create_bitmap:绘制位图。 create_image:绘制图片。 create_line():绘制直线。 create_polygon:绘制多边形。 create_text:绘制文字。 create_window:绘制组件。 Canvas 的坐标系统是绘图的基础,其中点 (0,0) 位于 Canvas 组件的左上角,X 轴水平向右延伸,Y 轴垂直向下延伸。
image − 创建图像 filename=PhotoImage(file="sunshine.gif")image=canvas.create_image(50,50,anchor=NE,image=filename) line − 创建线条 line=canvas.create_line(x0,y0,x1,y1,...,xn,yn,options) oval − 创建一个圆 oval=canvas.create_oval(x0,y0,x1,y1,options) ...
image = canvas.create_image(10, 10, anchor='nw', image=image_file) 加载图片,设置图片路径,放在画布中,anchor参数控制锚点-即图片相对于哪个位置进行摆放,锚点参数如下图所示,(10,10)表示相对于锚点的坐标。 x0, y0, x1, y1= 50, 50, 80, 80 # 设定图形位置坐标 ...
canvas.create_image(100, 100, image=photo, activeimage=image) canvas.pack(anchor=tk.CENTER, expand=True) root.mainloop() 使用activeimage参数,可以指定另一张图片,当鼠标指针移到图片上时,实现图片切换效果。 绘制文字 import tkinter as tk root = tk.Tk() ...
canvas.create_image(15,15,anchor=NW,image=frame) # label.configure(image = frame) # 显示label方法当前帧的图片 # 0.1秒(500毫秒)之后继续执行定时器函数(update) ifself.isplaying: self.root.after(self.time,update,idx%numIdx) else: self.stop_idx=idx ...
image − 创建图像 filename=PhotoImage(file="sunshine.gif")image=canvas.create_image(50,50,anchor=NE,image=filename) line − 创建线条 line=canvas.create_line(x0,y0,x1,y1,...,xn,yn,options) oval − 创建一个圆 oval=canvas.create_oval(x0,y0,x1,y1,options) ...