from tkinter import *
from tkinter import filedialog as fd, ttk
from PIL import Image, ImageTk
window = Tk()
window.title("Watermarking App")
window.geometry("1920x1280")
window.resizable(0, 0)
window.option_add("*tearOff", FALSE)
def open_file():
global image
global canvas
file_path = fd.askopenfilename()
canvas = Canvas(bg="white", width=1200, height=1200)
canvas.pack(expand=True)
image = ImageTk.PhotoImage(Image.open(f"{file_path}"))
canvas.create_image(0, 0, anchor=NW, image=image)
def font_changed(font):
label["font"] = font
def save_file():
canvas.postscript(file="photo.ps", colormode="color")
img = Image.open("photo.ps")
img.save("photo.png", "png")
def select_font():
window.tk.call("tk", "fontchooser", "configure", "-font", label["font"], "-command", window.register(font_changed))
window.tk.call("tk", "fontchooser", "show")
def draw_text():
text = label["text"]
font = label["font"]
canvas.create_text(100, 210, text=f"{text}", font=f"{font}", fill="black")
def write_mark():
label["text"] = editor.get("1.0", "end")
def change_coord():
pass
main_menu = Menu()
file_menu = Menu()
edit_menu = Menu()
main_menu.add_cascade(label="Файл", menu=file_menu)
main_menu.add_cascade(label="Изменить", menu=edit_menu)
main_menu.add_cascade(label="View")
file_menu.add_command(label="Открыть", command=open_file)
file_menu.add_command(label="Сохранить", command=save_file)
file_menu.add_separator()
file_menu.add_command(label="Выйти")
edit_menu.add_command(label="Изменить текст", command=write_mark)
edit_menu.add_command(label="Выбор шрифта", command=select_font)
edit_menu.add_command(label="Добавить текст", command=draw_text)
label = ttk.Label(text="Как будет выглядеть текст на изображении")
label.pack(anchor=N, pady=10)
editor = Text(height=3)
editor.pack(anchor=N, pady=10)
window.config(menu=main_menu)
window.mainloop()