Reload the columns in the sort dropdown menu automatically when the user creates a new…
- User
Reload the columns in the sort dropdown menu automatically when the user creates a new column. I mean when the user uses the tksheet building function to add a new column. Do Not add a new button. Lets think step by step. Python 3.12 Code: from tksheet import Sheet import tkinter as tk from tkinter import ttk
def custom_sort_design(master, style: ttk.Style, headers=None, sort_orders=None, colors=None): """Creates a custom sort frame with comboboxes for columns and sort order, includes secondary sort.""" sort_frame = ttk.Frame(master, style="Custom.TFrame")
code# Configure styles style.configure("Custom.TFrame", background=colors["background"], relief="flat", borderwidth=0) style.configure("TCombobox", relief="flat", borderwidth=0, background=colors["background"], fieldbackground=colors["background"]) style.map("TCombobox", fieldbackground=[('readonly', colors["background"])], background=[('readonly', colors["background"])]) style.configure("Line.TFrame", background=colors["filter_line"]) # Create widgets for primary sort primary_column_combobox = ttk.Combobox(sort_frame, values=headers, width=10, font=('Arial', 10), state="readonly") primary_order_combobox = ttk.Combobox(sort_frame, values=sort_orders, width=10, font=('Arial', 10), state="readonly") # Create widgets for secondary sort secondary_column_combobox = ttk.Combobox(sort_frame, values=headers, width=10, font=('Arial', 10), state="readonly") secondary_order_combobox = ttk.Combobox(sort_frame, values=sort_orders, width=10, font=('Arial', 10), state="readonly") # Layout widgets primary_column_combobox.grid(row=0, column=0, padx=5, pady=2, sticky='ew') primary_order_combobox.grid(row=0, column=1, padx=5, pady=2, sticky='ew') secondary_column_combobox.grid(row=1, column=0, padx=5, pady=2, sticky='ew') secondary_order_combobox.grid(row=1, column=1, padx=5, pady=2, sticky='ew') # Prevent text selection in comboboxes for combobox in (primary_column_combobox, primary_order_combobox, secondary_column_combobox, secondary_order_combobox): combobox.bind("<FocusIn>", lambda event: event.widget.selection_clear()) # Configure column weights sort_frame.columnconfigure((0, 1), weight=1) return ( sort_frame, primary_column_combobox, primary_order_combobox, secondary_column_combobox, secondary_order_combobox ) - Assistant
- User
Traceback (most recent call last): File "D:\Bilder\Python\Database\Sort - Kopie.py", line 142, in app = SortableSheetApp() File "D:\Bilder\Python\Database\Sort - Kopie.py", line 100, in init self.sheet.bind('', self.update_comboboxes) ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Zarathustra\AppData\Local\Programs\Python\Python313\Lib\site-packages\tksheet\sheet.py", line 983, in bind self.MT.bind(binding, func, add=add) ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Zarathustra\AppData\Local\Programs\Python\Python313\Lib\tkinter_init_.py", line 1545, in bind return self._bind(('bind', self.w), sequence, func, add) ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Zarathustra\AppData\Local\Programs\Python\Python313\Lib\tkinter_init.py", line 1499, in _bind self.tk.call(what + (sequence, cmd)) ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^ _tkinter.TclError: bad event type or keysym "HeaderChanged"
- Assistant