Ширина столбцов «Автоподбор» — PythonPython

Программы на Python
Ответить
Anonymous
 Ширина столбцов «Автоподбор» — Python

Сообщение Anonymous »

Я пытаюсь настроить ширину столбца с автоподбором, и приведенный ниже код работает очень хорошо, но автоподбор происходит только в том случае, если я не нахожусь в представлении вкладок. Есть ли способ обойти это?

Код: Выделить всё

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}")
код ниже — это когда я использую «автоподбор»

Код: Выделить всё

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')

market = values[2]
strike = values[6]
intermediate_ccy = values[8]
cntpy = values[18]
premiumperunit = values[19]

strike_result = strike_formula_option(market, strike, intermediate_ccy, commodities_ric, commodities_factor, tabview)
cnpj_cliente = lookup(cntpy, cntpy_acronym, cntpy_taxid)
decimal_strike_result = decimal_formula_option(market, strike, intermediate_ccy, commodities_ric, commodities_factor, tabview)
base_value = int(values[9].replace(",", "").replace("-", ""))
pu_result = pu_formula_option(market, premiumperunit, intermediate_ccy, commodities_ric, commodities_factor, tabview)
pu_decimal_result = pudecimal_formula_option(market, premiumperunit, intermediate_ccy, commodities_ric, commodities_factor, tabview)

line = [
"OPTION",
"1",
"0002",
"OFCV" if values[4] == "Option (Put)" else "OFCC",
values[23],
"00001",
"0000",
"P2" if values[3] == "Sell" else "P1",
rept(" ", 3),
safe_date_conversion(values[1]),
safe_date_conversion(values[10]),
strike_result,
decimal_strike_result,
pu_result,
pu_decimal_result,
rept(" ", 8),
]

table_fileoption_client.insert("", "end", values=line)
adjust_column_widths(table_fileoption_client, columns_option_file, tabview)
[1]:[когда вкладка активна]https://i.sstatic.net/f5IOTNv6.png
[2] :[когда вкладка не активна] https://i.sstatic.net/tCksiDMy.png

Подробнее здесь: https://stackoverflow.com/questions/792 ... dth-python
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»