网址如下:https://stackoverflow.com/questions/9886274/how-can-i-convert-canvas-content-to-an-image 介绍第1种方法,首先将canvas的图像保存为postscript类型文件代码如下,扩展名可为ps或esp。代码有修改,能够正确运行。 from tkinter import * root = Tk() cv = Canvas(root) cv.create_rectangle(10,10,50...
我有这段代码,它让用户在画布上绘图,并将其保存为jpeg文件。
运行结果如下: image.png 2.2 canve画布 importtkinter app=tkinter.Tk()app.title('my window')app.geometry('200x200')# 创建画布,并设置背景颜色,以及画布长宽canvas=tkinter.Canvas(app,bg='#b9b9f9',height=150,width=200)# 定义图片image_file=tkinter.PhotoImage(file='1.gif')# 将图片放置在画布上i...
canvas_dc.DrawCircle(x, y, r) # now put the canvas drawing into a bitmap to display it # remember the canvas is on top of the draw_bmp self.statbmp.SetBitmap(draw_bmp) def save_image(self): """save the drawing""" finished_image = self.statbmp.GetBitmap() #finished_image.Sa...
图三十九 简单的 Canvas 绘图 关于Canvas 提供的绘制方法如下: (1)、create_rectangle():绘制矩形。 (2)、create_oval():绘制椭圆(包括圆,圆是椭圆的特例)。 (3)、create_arc():绘制绵弧形。 (4)、create_bitmap():绘制位置。 (5)、create_image():绘制图片。
import tkinter as tk from tkinter import PhotoImage # 创建主窗口 root = tk.Tk() root.title("Tkinter Canvas Example") # 创建 Canvas 组件 canvas = tk.Canvas(root, width=400, height=300, bg="white") canvas.pack() # 绘制直线 canvas.create_line(10, 20, 200, 20, fill="blue", width=...
import tkinter as tk window = tk.Tk() window.title('微信公众号:愤怒的it男') window.iconbitmap('favicon.ico') window.geometry('450x300') image = tk.PhotoImage(file='image.png') label_image = tk.Label(window, image=image, width=150, height=150, borderwidth=1, relief='solid') ...
canvas_dc.DrawCircle(x, y, r) # now put the canvas drawing into a bitmap to display it # remember the canvas is on top of the draw_bmp self.statbmp.SetBitmap(draw_bmp) def save_image(self): """save the drawing""" finished_image = self.statbmp.GetBitmap() ...
self.save_image() def draw_image(self): # select the width and height of the blank bitmap # should fit the client frame w, h = 340, 340 # create the blank bitmap as a draw background draw_bmp = wx.EmptyBitmap(w, h) # create the canvas on top of the draw_bmp canvas_dc =...
Canvas的使用(create_text填写文字) Canvas的使用(绘制椭圆和多边形,扇形) Canvas的使用(五角星绘制:数学math模块回顾) Canvas的使用(事件绑定) Canvas的使用(create_bitmap创建) Canvas的使用(create_image图片的使用) Canvas的使用(create_window组件的使用) ...