#TkinterPaint
Код из видео:
from tkinter import *
import PIL
from PIL import Image, ImageDraw
from tkinter import messagebox
from random import *
def save():
filename = f'image_{randint(0, 10000)}.png'
image1.save(filename)
messagebox.showinfo('Сохранение', 'Сохранено под названием %s' % filename)
def activate_paint(event):
x1, y1 = (event.x - 2), (event.y - 2)
x2, y2 = (event.x + 2), (event.y + 2)
cv.create_line(x1, y1, x2, y2, fill='black', width=5)
draw.line((x1, y1, x2, y2), fill='black', width=5)
root = Tk()
root.title("Рисовалка")
root.resizable(width=False, height=False)
cv = Canvas(root, width=1280, height=720, bg='white')
image1 = PIL.Image.new('RGB', (1280, 720), 'white')
draw = ImageDraw.Draw(image1)
cv.bind('<B1-Motion>', activate_paint)
cv.pack(expand=1, fill=BOTH)
btn_save = Button(text="save", command=save, bg='black', fg='white', font=('Comic Sans MS', 30))
btn_save.pack()
root.mainloop()
Код из видео:
from tkinter import *
import PIL
from PIL import Image, ImageDraw
from tkinter import messagebox
from random import *
def save():
filename = f'image_{randint(0, 10000)}.png'
image1.save(filename)
messagebox.showinfo('Сохранение', 'Сохранено под названием %s' % filename)
def activate_paint(event):
x1, y1 = (event.x - 2), (event.y - 2)
x2, y2 = (event.x + 2), (event.y + 2)
cv.create_line(x1, y1, x2, y2, fill='black', width=5)
draw.line((x1, y1, x2, y2), fill='black', width=5)
root = Tk()
root.title("Рисовалка")
root.resizable(width=False, height=False)
cv = Canvas(root, width=1280, height=720, bg='white')
image1 = PIL.Image.new('RGB', (1280, 720), 'white')
draw = ImageDraw.Draw(image1)
cv.bind('<B1-Motion>', activate_paint)
cv.pack(expand=1, fill=BOTH)
btn_save = Button(text="save", command=save, bg='black', fg='white', font=('Comic Sans MS', 30))
btn_save.pack()
root.mainloop()