How to fine-tune column widths of a table displayed on a tkinter frame using pandastable?

752 Views Asked by At

I'm placing a pandas dataframe, df, on a tkinter frame, my_frame, using the pandastable package. The dataframe has four columns and, despite looking through the pandastable documention, I'm struggling to modify the column widths so that none of the column headers are truncated. Here's my relevant code, where my dataframe, df has already been created.

 from pandastable import Table, config
 table = Table(my_frame,dataframe=df,width=425,height=275,showtoolbar=False)
 options=config.load_options() # use config to change fontsize option
 options={'fontsize':18}
 config.apply_options(options,table)

 # Now I try to adjust widths of four columns:
 table.columnwidths={'Channel':25,'Start (sec)':75,'Stop (sec)':75,'Peak Frequency 
 (Hz)':250}

It seems no matter what I do, widths of the 'Start' and 'Stop' columns don't expand, which truncates their column headers as in the image below. I've tried increasing them from 75 to 80 to 85, etc., while increasing the overall width of table correspondingly, but I can't get things to work the way I want.enter image description here

1

There are 1 best solutions below

0
fishbacp On

This seemed to work:

pt=Table(table_frame,dataframe=df,width=450,height=275)
options=config.load_options()

options={'fontsize':18,'cellwidth': 100}
config.apply_options(options,pt)

pt.columnwidths['Peak Frequency (Hz)'] = 225
pt.columnwidths['Channel'] = 25

Default font is 18, and we override just two of the columns.