import tkinter as tk from tkinter import ttk class FormFrame(ttk.Frame): """Frame for selecting the SVG file.""" def __init__(self, parent, file_path_var, browse_command, **kwargs): """ Initialize the Form Frame. Args: parent: The parent widget. file_path_var (tk.StringVar): Variable to hold the SVG file path. browse_command (callable): Command to execute when Browse button is clicked. **kwargs: Additional arguments for ttk.Frame. """ super().__init__(parent, padding=10, **kwargs) self.file_path_var = file_path_var self.browse_command = browse_command self._create_widgets() def _create_widgets(self): """Create the widgets for the form frame.""" ttk.Label(self, text="SVG File:").grid(row=0, column=0, sticky=tk.W, pady=2, padx=5) file_entry = ttk.Entry(self, textvariable=self.file_path_var, width=60) file_entry.grid(row=0, column=1, sticky=tk.EW, pady=2) browse_button = ttk.Button(self, text="Browse...", command=self.browse_command) browse_button.grid(row=0, column=2, padx=5, pady=2) # Configure column weights for expansion self.columnconfigure(1, weight=1) # Example usage (for testing) if __name__ == '__main__': # Import filedialog only needed for the test case from tkinter import filedialog root = tk.Tk() root.title("Form Frame Test") root.geometry("500x100") # Style for testing style = ttk.Style() style.theme_use('clam') style.configure('TFrame', background='#f0f0f0') style.configure('TLabel', background='#f0f0f0') # Example variables and command file_path = tk.StringVar(value="/path/to/your/file.svg") def test_browse(): print("Browse button clicked!") # In real use, this would open a file dialog new_path = filedialog.askopenfilename(title="Select SVG", filetypes=[("SVG", "*.svg")]) if new_path: file_path.set(new_path) # Create and pack the frame form_frame_component = FormFrame(root, file_path_var=file_path, browse_command=test_browse) form_frame_component.pack(fill=tk.X, padx=10, pady=10) root.mainloop()