Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ it will automatically save over the current text file when you hit page up or pa

It's probably buggy so might wanna back up your files first in another directory.

I've just hardcoded the display resolution to 512x768, cause that's what I was working with and I couldn't be bothered figuring out how to make it dynamic based on the images. If you can tell me how please do and I'll update it.
Only been tested in windows 10, with python 3.11
Only been tested in
* windows 10, with python 3.11
* ubuntu 22.04 with python 3.10
72 changes: 39 additions & 33 deletions image tag editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,27 @@
# Create a variable to keep track of the current image index
current_image_index = 0


canvas = tk.Tk()
canvas.grid()
canvas.geometry("1448x768")
# canvas.geometry("1448x768") # no predefined size, will take what's inside size
canvas.title("tag editor")
canvas.config(bg='white')

frame = tk.Frame(canvas)
frame.grid(row=0, column=0, sticky="nsew")
# Create frame to hold the text editor and buttons
text_frame = Frame(canvas, bg = "#1e1319")
text_frame.grid(row=0, column=1, sticky="nsew")

# label for image display
label = Label(canvas)
label.grid(row=0,column=0,sticky="nsew")

# make re-sizable
canvas.rowconfigure(0, weight=1)
canvas.columnconfigure(0, weight=0)
canvas.columnconfigure(1, weight=1)

# Create a bottom frame to hold the text editor and image
text_frame = Frame(frame)
text_frame.grid(row=1, column=1, sticky="ew")
text_frame.grid_rowconfigure(0, weight=0)
text_frame.grid_columnconfigure(1, weight=0)
text_frame.rowconfigure(0, weight=1)
text_frame.columnconfigure(1, weight=1)


def create_text_file(text, file_path):
Expand All @@ -58,7 +63,7 @@ def update_text_file(text, file_path):



# Function to update the image displayed in the
# Function to update the image displayed in the
def update_image():
global current_image
if current_image:
Expand All @@ -74,13 +79,16 @@ def update_image():
create_text_file("", current_text_file)
print("created " + image_names[current_image_index] + ".txt")

# resize image, but keep ratio
width = 512
ratio = width / float(img.size[0])
height = int (float(img.size[1]) * ratio)
print ("resize image for display to %dx%d with ratio %.2f" % (width, height, ratio) )

img = img.resize((512, 768), Image.LANCZOS)
img = img.resize((width, height), Image.LANCZOS)
img = ImageTk.PhotoImage(img)


label = Label(text_frame, image=img)
label.grid(row=0,column=0,sticky="nsew")
label.configure(image=img)
label.image = img # Keep a reference to the image


Expand All @@ -106,31 +114,31 @@ def on_key_press(event):


def load_text_file(file):
with open(file, "r") as f:
with open(file, "r") as f:
content = f.read()
entry.insert(INSERT, content)

def save_text_file(file):
text = str(entry.get(1.0, END))
with open(file, "w") as f:
with open(file, "w") as f:
f.write(text)

def clearFile():
entry.delete(1.0, END)

def saveFileButton():
new_file = asksaveasfile(mode = 'w', filetype = [('text files', '.txt')])
new_file = asksaveasfile(mode = 'w', filetypes = [('text files', '.txt')])
if new_file is None:
return
text = str(entry.get(1.0, END))
new_file.write(text)
new_file.close()

def openFileButton():
file = askopenfile(mode = 'r', filetype = [('text files', '*.txt')])
file = askopenfile(mode = 'r', filetypes = [('text files', '*.txt')])
if file is not None:
content = file.read()
entry.insert(INSERT, content)
entry.insert(INSERT, content)

def clearFileButton():
entry.delete(1.0, END)
Expand All @@ -141,29 +149,27 @@ def saveAndExitButton():
exit()



# Create a top frame to hold the buttons
button_frame = Frame(text_frame, bg="#1e1319")
button_frame.grid(row=0, column=1, sticky="nsew")
button_frame.grid_rowconfigure(0, weight=1)
button_frame.grid_columnconfigure(1, weight=0)
button_frame.grid_columnconfigure(2, weight=0)
button_frame.grid_columnconfigure(3, weight=1)
button_frame.grid(row=1, column=1, sticky="se")

# for c in range(0,5):
# button_frame.columnconfigure(c, weight=1)

b5 = Button(button_frame, text=" Save and Exit ", bg = "#4f2d3f", command = saveAndExitButton)
b4 = Button(button_frame, text=" Exit ", bg = "#4f2d3f", command = exit)
b3 = Button(button_frame, text=" Clear ", bg = "#4f2d3f", command = clearFileButton)
b2 = Button(button_frame, text=" Save ", bg = "#4f2d3f", command = saveFileButton)
b1 = Button(button_frame, text=" Open ", bg = "#4f2d3f", command = openFileButton)

b5.grid(row=1, column=4, padx=20, pady=20, sticky="W")
b4.grid(row=1, column=3, padx=20, pady=20, sticky="W")
b3.grid(row=1, column=2, padx=20, pady=20, sticky="W")
b2.grid(row=1, column=1, padx=20, pady=20, sticky="W")
b1.grid(row=1, column=0, padx=(450, 20), pady=20, sticky="W")
b5.grid(row=1, column=4, padx=10, pady=20, sticky="E")
b4.grid(row=1, column=3, padx=20, pady=20, sticky="E")
b3.grid(row=1, column=2, padx=20, pady=20, sticky="E")
b2.grid(row=1, column=1, padx=20, pady=20, sticky="E")
b1.grid(row=1, column=0, padx=20, pady=20, sticky="E")

entry = Text(text_frame, wrap = WORD, bg = "#281b22", fg="#d8adc3", insertbackground="yellow", font = ("poppins", 15), padx=10, pady=10)
entry.grid(row=0,column=1,sticky="nsew", padx=15, pady=(15, 60))
entry = Text(text_frame, wrap = WORD, bg = "#281b22", fg="#d8adc3", insertbackground="yellow", font = ("poppins", 15))
entry.grid(row=0,column=1,sticky="nsew", padx=10, pady=10)

update_image()
canvas.mainloop()
canvas.mainloop()