You are a Python programmer tasked with refactoring code. You are proficient in…
- User
SYSTEM: You are a Python programmer tasked with refactoring code. You are proficient in Python 3.12 and use modern features where appropriate. Your code is clear, easy to read, and free of unnecessary verbosity. You follow PEP 8, 20 and 257 to ensure high quality python code. You remove comments and instead focus on simple and clear one line docstrings to describe every function. USER: import tkinter as tk from tksheet import Sheet import json from pathlib import Path --- Utility Functions ---
def set_dpi_awareness(): """Enable DPI awareness to ensure high DPI settings are supported.""" try: import ctypes ctypes.windll.shcore.SetProcessDpiAwareness(1) except Exception as e: print(f"Error setting DPI awareness: {e}") --- GUI ---
class TableApp: def init(self, root): self.root = root self.root.title("Table Editor with Sidebar") self.root.geometry("1280x720")
codeself.sidebar = tk.Frame(root, width=200, bg='#F7F8FC', bd=0, relief='flat') self.sidebar.pack(expand=False, fill='y', side='left', anchor='nw') # Create a white field to serve as a visual separator self.separator = tk.Frame(root, width=100, bg='white', bd=0, relief='flat') self.separator.pack(expand=False, fill='y', side='left', anchor='nw') self.main_frame = tk.Frame(root) self.main_frame.pack(expand=True, fill='both', side='right') self.header_frame = tk.Frame(self.main_frame, height=50, bg='white') self.header_frame.pack(fill='x') self.filter_label = tk.Label(self.header_frame, text="Filter:", bg='white', anchor="w") self.filter_label.pack(side='left', padx=5, pady=10) self.filter_entry = tk.Entry(self.header_frame) self.filter_entry.pack(side='left', padx=5, pady=10) self.filter_entry.bind("<KeyRelease>", lambda event: self.apply_filter()) self.table_frame = tk.Frame(self.main_frame, bg='white') self.table_frame.pack(expand=True, fill='both') self.new_table_button = tk.Button( self.sidebar, text="New Table", command=self.create_new_table, bg='#F7F8FC', borderwidth=0, highlightthickness=0, relief='flat' ) self.new_table_button.pack(padx=10, pady=10, fill='x') # --- Updated Listbox with New Selection Background --- self.table_listbox = tk.Listbox( self.sidebar, bg='#F7F8FC', borderwidth=0, highlightthickness=0, relief='flat', selectbackground='#EAEDEF', # Updated selection background color selectforeground='black', # Ensures text color remains black when selected activestyle='none' ) self.table_listbox.pack(expand=True, fill='both', padx=10, pady=10) self.table_listbox.bind('<<ListboxSelect>>', self.load_selected_table) self.table_listbox.bind('<Double-1>', self.begin_rename) self.save_file_dir = Path("tables") self.tables = {} self.original_data = {} self.rename_entry = None if not self.save_file_dir.exists(): self.save_file_dir.mkdir() self.load_tables() - Assistant
- User
Implement the ability to rename the headers of the spreedsheet
- Assistant
- User
the rename dialogue should oben on double click like for tables
- Assistant
- User
Use the following as guide on how torename the headers in tksheet; To rename headers in tksheet, you can use the headers() method. Here's how you can modify the headers:
codeSet the initial headers when creating the sheet:python sheet = tksheet.Sheet(root) sheet.headers(["Column 1", "Column 2", "Column 3"])
codeTo change the headers later:python new_headers = ["New Column 1", "New Column 2", "New Column 3"] sheet.headers(new_headers)
You can also modify individual header names:
python sheet.headers(["New Name"], index=0) # Change first column header
If you want to programmatically rename headers based on certain conditions, you can:
codeGet the current headers:python current_headers = sheet.headers()
codeModify the headers as needed:python new_headers = [h.upper() for h in current_headers] # Example: convert to uppercase
codeSet the new headers:python sheet.headers(new_headers)
Remember to update your UI after changing headers:
python sheet.refresh()
These methods allow you to dynamically rename headers in your tksheet table4 .
- Assistant
- User
I want the user to be able to do the renaming in the gui
- Assistant