Справочник Программиста
6.29K subscribers
1.36K photos
387 videos
64 files
1.71K links
По рекламе - @it_start_programmer
Мои курсы - @courses_from_it_start_bot
Сайт - https://it-start.online/
YouTube - https://www.youtube.com/@it_start
Реклама на бирже - https://telega.in/c/programmersGuide_1

Предложить идею: @it_start_suggestion_bot
Download Telegram
#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()