1
0 Комментариев
from PIL import Image, ImageTk
import fileinput
from tkinter.filedialog import askopenfilename
from tkinter.filedialog import*
  canvas_width = 700  # create global variable
canvas_height = 500  # create global variable
brush_size: int = 3  # set up size brush
color = "black"  # set up color
  def choose_file():
    path = askopenfilename()
    image = ImageTk.PhotoImage(Image.open(path))
    imagesprite = w.create_image(0, 0, image=image)
 '''
def choose_file():
    path = askopenfilename()
    image = ImageTk.PhotoImage(Image.open(path))
    imagesprite = w.create_image(400, 400, image=image)
'''
def paint(event):  # create fuction
    global brush_size
    global color
    x1 = event.x - brush_size
    x2 = event.x + brush_size
    y1 = event.y - brush_size
    y2 = event.y + brush_size
    w.create_oval(x1, y1, x2, y2,
                fill=color, outline=color)
 def brush_size_change(new_size):
    global brush_size
    brush_size = new_size
 def color_change(new_color):
    global color
    color = new_color
 root = Tk()  # create window
#root.geometry('1000x1000')  #задает размер холста
root.title('Photoshop')  # give the name of window
  w = Canvas(root, width=canvas_width,height=canvas_height, bg = 'white')  # создаем переменную и задаем параметры классу
w.pack()
w.bind("<B1-Motion>", paint)  # включаем мышку
  zagruzkaizo_btn = Button (text= 'Загрузить', width=10, command=lambda: choose_file()) #вызов функции загрузки
clear_btn = Button(text='Удалить все', width=10,
                 command=lambda: w.delete ("all"))
white_btn = Button(text='Стерка', width=10, bg="red",
                 command=lambda: color_change("white")) #кнопка
red_btn = Button(text='Красный', width=10,
                 command=lambda: color_change('red'))
black_btn = Button(text='Черный', width=10,
                 command=lambda: color_change("black"))
green_btn = Button(text='Зеленый', width=10,
                 command=lambda: color_change("green"))
five_btn = Button (text="Размер 5", width=10, command=lambda: brush_size_change(5))
two_btn = Button (text="Размер 2", width=10, command=lambda: brush_size_change(2))
ten_btn = Button (text="Размер 10", width=10, command=lambda: brush_size_change(10))
 w.grid(row=2, column=0, padx=5, columnspan=7, pady=5, sticky=E+W+S+N)
w.columnconfigure(6, weight=1)
w.rowconfigure(2, weight=1)
 zagruzkaizo_btn.grid(row=0, column=3)
red_btn.grid(row=0, column=0) #местоположение
black_btn.grid(row=0, column=1)
green_btn.grid(row=0, column=2)
white_btn.grid(row=7, column=8)
clear_btn.grid(row=6, column=8)
five_btn.grid(row=4, column=8)
two_btn.grid(row=5, column=8)
ten_btn.grid(row=3, column=8)
 root.mainloop()  # call window


Добавить комментарий