简体   繁体   中英

How do I set different column widths for each column of a tktable?

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.

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)

The right answer is:

columnwidth={'0':7,'1':12,'2':20,'3':35,'4':15,'5':15,'6':22}
self.table.width(**columnwidth)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM