Я пытаюсь настроить ширину столбца с автоподбором, и приведенный ниже код работает очень хорошо, но автоподбор происходит только в том случае, если я не нахожусь в представлении вкладок. Есть ли способ обойти это?
from tkinter import ttk, Font
def adjust_column_widths(treeview, columns, tabview):
try:
font = Font()
for column in columns:
# Calculate the width of the column title
title_width = font.measure(column)
# Calculate the maximum width of the column content
content_width = max(
(font.measure(treeview.set(item, column)) for item in treeview.get_children('')),
default=0
)
# Set the final width of the column
final_width = max(title_width, content_width) # Add padding for clarity
treeview.column(column, width=final_width, anchor='center')
except Exception as e:
print(f"Error adjusting column widths: {e}")
Я пытаюсь настроить ширину столбца с автоподбором, и приведенный ниже код работает очень хорошо, но автоподбор происходит только в том случае, если я не нахожусь в представлении вкладок. Есть ли способ обойти это? [code]from tkinter import ttk, Font
def adjust_column_widths(treeview, columns, tabview): try: font = Font() for column in columns: # Calculate the width of the column title title_width = font.measure(column) # Calculate the maximum width of the column content content_width = max( (font.measure(treeview.set(item, column)) for item in treeview.get_children('')), default=0 )
# Set the final width of the column final_width = max(title_width, content_width) # Add padding for clarity treeview.column(column, width=final_width, anchor='center')
except Exception as e: print(f"Error adjusting column widths: {e}") [/code] код ниже — это когда я использую «автоподбор» [code]def populate_option_file(tabview, tab, existing_tabs): # Check if the "Monitor" tab already exists if "Arquivo B3" not in existing_tabs: # Initialize the operations monitor and get the tabviews file_b3(tabview, tab, existing_tabs) existing_tabs.append("Arquivo B3")
# Extract necessary data from the tables commodities_ric, commodities_factor, cntpy_taxid, cntpy_acronym = extract_table_data()
def rept(char, count): return char * count
# Process data for tabele_option_client for i, item in enumerate(table_fileoption_client.get_children(), start=3): values = table_fileoption_client.item(item, 'values')