2

I have a table made using Python 2.7 and tktable v1.1 that looks like the following:

class GUI (Tkinter.Tk):
    self.testTable = tktable.Table(self, rows = 30, cols = 30, state='disabled',titlecols=1,titlerows=1, \
                                   selectmode='extended', variable=self.tktableArray, selecttype='row', colstretchmode='unset', \
                                   maxwidth=500, maxheight=190, xscrollcommand = self.HScroll.set, yscrollcommand = self.VScroll.set) # Create the results table
    self.testTable.grid(column= 2, row = 6, columnspan = 4) # Add results table to the grid

Irrelevant code was left out in order to not throw a wall of code up. My desire here is to size the column widths independently for each column. For instance in column 0 I have only 3 digit numbers and in column 1 I have a 10 character word. I know that I could use

self.testTable.configure(colwidth=10)

to set the widths of the columns but that applies to all columns. Is there a way to do this on a per-column basis? And even better, is there a way to make the column widths fit to the contents of the column? Any help is appreciated.

nbro
  • 15,395
  • 32
  • 113
  • 196
thewill2live
  • 215
  • 2
  • 6

2 Answers2

4

I've never used a tktable, but a quick read of the tktable documentation shows there's a width() method on the table object. Have you tried that?

# set width of column 0 to 3, column 1 to 10
self.testTable.width(0,3,1,10)
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • Thank you so much. I was attacking this using self.testTable['width'] the whole time and couldn't get the adjustment to work. I had read the documentation on self.testTable.width but apparently not thoroughly enough. My first attempt with that command resulted in an error because I formatted the arguments as ((0,3),(1,10)) rather than in a flat list of numbers. I feel really foolish now. Thank you once again! – thewill2live Apr 01 '15 at 15:19
1

The right answer is:

columnwidth={'0':7,'1':12,'2':20,'3':35,'4':15,'5':15,'6':22}
self.table.width(**columnwidth)
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Abhi
  • 11
  • 1