Translate the exact Graphical design from code 1 (not the values for columns and…
- User
Translate the exact Graphical design from code 1 (not the values for columns and filters): import tkinter as tk from tkinter import ttk
def custom_tkinter_filter(master, headers=None, filter_types=None): # Create a Frame for the custom filter filter_frame = ttk.Frame(master) filter_frame.configure(style="Custom.TFrame")
# Define style for the widgets style = ttk.Style() style.configure("Custom.TFrame", background="white", relief="flat", borderwidth=1) style.configure("Custom.TCombobox", background="white") # Configure the widgets header_combobox = ttk.Combobox(filter_frame, values=headers, style="Custom.TCombobox") filtertype_combobox = ttk.Combobox(filter_frame, values=filter_types, style="Custom.TCombobox") filter_entry = ttk.Entry(filter_frame) # Layout using grid header_combobox.grid(row=0, column=0, padx=5, pady=5, sticky='ew') filtertype_combobox.grid(row=0, column=1, padx=5, pady=5, sticky='ew') filter_entry.grid(row=1, column=0, columnspan=2, padx=5, pady=5, sticky='ew') # Make the entry expand with the widget filter_frame.columnconfigure(0, weight=1) filter_frame.columnconfigure(1, weight=1) return filter_frameCreate a simple application window to demonstrate the widget function
if name == "main": root = tk.Tk() headers = ["Column1", "Column2", "Column3"] filter_types = ["Contains", "Equals", "Starts with"]
filter_widget = custom_tkinter_filter(root, headers, filter_types) filter_widget.pack(padx=10, pady=10, fill='x') root.mainloop()Into code 2: def _create_filter_controls(self, parent: tk.Frame) -> None: """Create and add filter controls to the lower header frame using the custom design."""
# Define style configuration consistent with custom_tkinter_filter style = ttk.Style() # Frame style for clean aesthetic style.configure("Custom.TFrame", background="white", relief="flat", borderwidth=1) # Combobox style with active border color and custom arrow style.configure("Custom.TCombobox", fieldbackground="white", background="white") style.map("Custom.TCombobox", fieldbackground=[("readonly", "white")], selectbackground=[("readonly", "white")], selectforeground=[("readonly", "white")], lightcolor=[("focus", "blue")]) # Entry style configurations style.configure("Custom.TEntry", fieldbackground="white", bordercolor="gray") # Create a filter frame using the custom style filter_frame = ttk.Frame(parent, style="Custom.TFrame") filter_frame.grid(row=0, column=0, columnspan=5, padx=5, pady=5, sticky='ew') # Header selection Combobox self.filter_header_dropdown = ttk.Combobox( filter_frame, textvariable=self.filter_header_var, values=["Column1", "Column2", "Column3"], # Populate with real header values style="Custom.TCombobox", state="readonly") self.filter_header_dropdown.grid(row=0, column=0, padx=5, pady=5, sticky='ew') # Filter type Combobox self.filter_option_dropdown = ttk.Combobox( filter_frame, textvariable=self.filter_option_var, values=["Contains", "Equals", "Starts with"], style="Custom.TCombobox", state="readonly") self.filter_option_dropdown.grid(row=0, column=1, padx=5, pady=5, sticky='ew') # Filter text entry field self.filter_text_entry = ttk.Entry( filter_frame, textvariable=self.filter_text_var, style="Custom.TEntry") self.filter_text_entry.grid(row=1, column=0, columnspan=2, padx=5, pady=5, sticky='ew') # Make the text entry expand with the widget filter_frame.columnconfigure(0, weight=1) filter_frame.columnconfigure(1, weight=1) # Bind actions to the widgets self.filter_header_dropdown.bind("<<ComboboxSelected>>", lambda _: self.apply_filter()) self.filter_option_dropdown.bind("<<ComboboxSelected>>", self.update_filter_text_state) self.filter_text_entry.bind("<Return>", lambda _: self.apply_filter()) - Assistant