小编Bac*_*chi的帖子

Python - Tkinter - Paint:如何平滑地绘制并用不同的名称保存图像?

我制作了一个绘画程序,但我无法顺利绘制并且每次都用不同的名称保存图像。请帮忙!

from tkinter import *
# by Canvas I can't save image, so i use PIL
import PIL
from PIL import Image, ImageDraw


def save():
    filename = 'image.png'
    image1.save(filename)

def paint(event):
    x1, y1 = (event.x), (event.y)
    x2, y2 = (event.x + 1), (event.y + 1)
    cv.create_oval((x1, y1, x2, y2), fill='black', width=10)
    #  --- PIL
    draw.line((x1, y1, x2, y2), fill='black', width=10)


root = Tk()

cv = Canvas(root, width=640, height=480, bg='white')
# --- PIL
image1 = PIL.Image.new('RGB', (640, 480), 'white')
draw = …
Run Code Online (Sandbox Code Playgroud)

tkinter paint python-imaging-library python-3.x tkinter-canvas

1
推荐指数
1
解决办法
1万
查看次数