diff --git a/gui/assets/TextBox_Bg.png b/gui/assets/TextBox_Bg.png index 514d9d6d..b1f75333 100644 Binary files a/gui/assets/TextBox_Bg.png and b/gui/assets/TextBox_Bg.png differ diff --git a/tkdesigner/figma/custom_elements.py b/tkdesigner/figma/custom_elements.py index 6980f6a4..69d88a58 100644 --- a/tkdesigner/figma/custom_elements.py +++ b/tkdesigner/figma/custom_elements.py @@ -13,17 +13,21 @@ def __init__(self, node, frame, image_path, *, id_): self.id_ = id_ def to_code(self): + identify = self.id_ + name = self.get("name").strip().lower() + if '_' in name: + identify = name.split('_')[1] return f""" -button_image_{self.id_} = PhotoImage( - file=relative_to_assets("{self.image_path}")) -button_{self.id_} = Button( - image=button_image_{self.id_}, +button_image_{identify} = ImageTk.PhotoImage(Image.open( + relative_to_assets("{self.image_path}"))) +button_{identify} = Button( + image=button_image_{identify}, borderwidth=0, highlightthickness=0, - command=lambda: print("button_{self.id_} clicked"), + command=lambda: print("button_{identify} clicked"), relief="flat" ) -button_{self.id_}.place( +button_{identify}.place( x={self.x}, y={self.y}, width={self.width}, @@ -109,13 +113,17 @@ def __init__(self, node, frame, image_path, *, id_): self.id_ = id_ def to_code(self): + identify = self.id_ + name = self.get("name").strip().lower() + if '_' in name: + identify = name.split('_')[1] return f""" -image_image_{self.id_} = PhotoImage( - file=relative_to_assets("{self.image_path}")) -image_{self.id_} = canvas.create_image( +image_image_{identify} = ImageTk.PhotoImage(Image.open( + relative_to_assets("{self.image_path}"))) +image_{identify} = canvas.create_image( {self.x}, {self.y}, - image=image_image_{self.id_} + image=image_image_{identify} ) """ @@ -143,25 +151,28 @@ def __init__(self, node, frame, image_path, *, id_): self.entry_x, self.entry_y = self.position(frame) self.entry_x += corner_radius - - self.entry_type = TEXT_INPUT_ELEMENT_TYPES.get(self.get("name")) + self.entry_type = TEXT_INPUT_ELEMENT_TYPES.get(self.get("name").split("_")[0]) def to_code(self): + identify = self.id_ + name = self.get("name").strip().lower() + if '_' in name: + identify = name.split('_')[1] return f""" -entry_image_{self.id_} = PhotoImage( - file=relative_to_assets("{self.image_path}")) -entry_bg_{self.id_} = canvas.create_image( +entry_image_{identify} = ImageTk.PhotoImage(Image.open( + relative_to_assets("{self.image_path}"))) +entry_bg_{identify} = canvas.create_image( {self.x}, {self.y}, - image=entry_image_{self.id_} + image=entry_image_{identify} ) -entry_{self.id_} = {self.entry_type}( +entry_{identify} = {self.entry_type}( bd=0, bg="{self.bg_color}", fg="#000716", highlightthickness=0 ) -entry_{self.id_}.place( +entry_{identify}.place( x={self.entry_x}, y={self.entry_y}, width={self.entry_width}, diff --git a/tkdesigner/figma/frame.py b/tkdesigner/figma/frame.py index 70e3611f..ce9e3d36 100644 --- a/tkdesigner/figma/frame.py +++ b/tkdesigner/figma/frame.py @@ -41,7 +41,7 @@ def create_element(self, element): f"{{ name: {element_name}, type: {element_type} }}" ) - if element_name == "button": + if element_name == "button" or element_name.startswith("button_"): self.counter[Button] = self.counter.get(Button, 0) + 1 item_id = element["id"] @@ -55,7 +55,7 @@ def create_element(self, element): return Button( element, self, image_path, id_=f"{self.counter[Button]}") - elif element_name in ("textbox", "textarea"): + elif element_name in ("textbox", "textarea") or any(element_name.startswith(prefix) for prefix in ('textbox_', 'textarea_')): self.counter[TextEntry] = self.counter.get(TextEntry, 0) + 1 item_id = element["id"] @@ -69,7 +69,7 @@ def create_element(self, element): return TextEntry( element, self, image_path, id_=f"{self.counter[TextEntry]}") - elif element_name == "image": + elif element_name == "image" or element_name.startswith("image_"): self.counter[Image] = self.counter.get(Image, 0) + 1 item_id = element["id"] diff --git a/tkdesigner/template.py b/tkdesigner/template.py index b9e67b30..9d2da750 100644 --- a/tkdesigner/template.py +++ b/tkdesigner/template.py @@ -8,6 +8,7 @@ # from tkinter import * # Explicit imports to satisfy Flake8 from tkinter import Tk, Canvas, Entry, Text, Button, PhotoImage +from PIL import Image, ImageTk OUTPUT_PATH = Path(__file__).parent