Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the names of tkintertable rows

Tags:

python

tkinter

So I'm working on an embedded user editable table in tkinter. I'd like to give the PlateLayout class a custom set of rows instead of the default 1,2,3...

import Tkinter as tk
from tkintertable.Tables import TableCanvas


class PlateLayout:
    def __init__(self, parent):
        self.parent = parent

    def make_frame(self):
        self.the_frame = tk.Frame(self.parent)
        self.the_frame.pack()

    def make_table(self):
        self.the_table = TableCanvas(self.the_frame, rows=8, cols=12)
        self.the_table.createTableFrame()

    def make_all(self):
        self.make_frame()
        self.make_table()

root_win = tk.Tk()
app = PlateLayout(root_win)
app.make_all()
root_win.mainloop()

I've seen screen shots of renamed columns, but haven't found a reference as to how to do this programmatically.

like image 696
Kyrubas Avatar asked Nov 20 '25 13:11

Kyrubas


1 Answers

This is referenced from https://code.google.com/p/tkintertable/wiki/Usage#Change_column_labels

A quick change to your code will let you set custom labels;

....
def make_table(self):
    self.the_table = TableCanvas(self.the_frame, rows=8, cols=12)

    # Lets peek at the current labels, delete in production
    print self.the_table.model.columnlabels
    self.the_table.model.columnlabels['1'] = "Custom Col"

    self.the_table.createTableFrame()
....
like image 180
harvey Avatar answered Nov 23 '25 03:11

harvey