To create a more visually pleasing GUI for adding a new product, we can make use of padding, alignment, and perhaps even widgets' frames to better organize the layout. I'll provide a revised version of your function with these elements in mind:
import tkinter as tk
from tkinter import ttk
# Assuming your self._scrape and self._addd functions are defined elsewhere
# Also assuming 'colors_price' and 'min_min_price' are defined
def _add_item_window(self):
# Create a new window
add_window = tk.Toplevel()
add_window.title("Add New Product")
add_window.geometry('400x300') # Adjusted for better geometry
add_window.resizable(True, True)
# Frame for better organization and padding
form_frame = ttk.Frame(add_window, padding="10 10 10 10")
form_frame.grid(column=0, row=0, sticky=(tk.W, tk.E, tk.N, tk.S))
form_frame.columnconfigure(0, weight=1)
form_frame.rowconfigure(0, weight=1)
# URL Link
url_label = ttk.Label(form_frame, text="URL Link:")
url_label.grid(row=0, column=0, sticky=tk.W)
url_entry = ttk.Entry(form_frame, width=50)
url_entry.grid(row=1, column=0, sticky=(tk.W, tk.E))
# Save (Check) Button
save_button = ttk.Button(form_frame, text="Check", command=lambda: self._scrape(url_entry.get(), add_window))
save_button.grid(row=2, column=0, pady=5, sticky=tk.W)
# Color Selection
color_label = ttk.Label(form_frame, text="Select Color:")
color_label.grid(row=3, column=0, sticky=tk.W)
n = tk.StringVar()
color_combo = ttk.Combobox(form_frame, values=colors_price, width=47, textvariable=n)
color_combo.grid(row=4, column=0, sticky=(tk.W, tk.E))
color_combo.current(0)
# Price Label
price_label = ttk.Label(form_frame, text='Price: ')
price_label.grid(row=5, column=0, sticky=tk.W)
price_ = ttk.Label(form_frame, text='')
price_.grid(row=6, column=0, sticky=tk.W)
price_.config(text=str(min_min_price))
# Number Selection
tk.Label(form_frame, text='Number:').grid(row=7, column=0, sticky=tk.W)
sp = tk.Spinbox(form_frame, from_=0, to=30, width=48)
sp.grid(row=8, column=0, sticky=(tk.W, tk.E))
# Add Button
add_button = ttk.Button(form_frame, text="ADD", command=lambda: self._addd(add_window))
add_button.grid(row=9, column=0, pady=5, sticky=tk.W)
# Adjust the window's row and column configurations for uniform spacing
for child in form_frame.winfo_children():
child.grid_configure(padx=5, pady=3)
In this revised version, the following adjustments were made:
-
Geometry and Spacing: The window size was slightly increased, and padding was added within a grid in a ttk.Frame to organize the widgets better and give them a bit of breathing room.
-
Frame Usage: A ttk.Frame (form_frame) was introduced to act as the primary container inside the window. This helps with managing padding and provides an easier way to manage widget layout adjustments in the future.
-
Sticky Options: The sticky parameter was applied to the grid method calls to align the widgets appropriately within their grid cells. This alignment ensures that the text fields and labels are properly spaced and aligned for a cleaner look.
-
Width Adjustment for Widgets: The width of the Combobox and the Spinbox was adjusted to ensure consistency with the layout and to fill the space more effectively.
Remember, the aesthetics of a GUI can be highly subjective, and further adjustments may be needed to align with your exact preferences or the requirements of your application's user interface.