2015-05-27 142 views
3

因此,我正在使用tkinter中的嵌入式用戶可編輯表。我想給PlateLayout類的自定義設置的行,而不是默認1,2,3 ......更改tkintertable行的名稱

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

我見過改名列的屏幕截圖,但還沒有找到一個參考至於如何以編程方式做到這一點。

回答

1

這是從https://code.google.com/p/tkintertable/wiki/Usage#Change_column_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() 
.... 
+0

這讓我足夠接近。我特別尋找的部分是'showkeynamesinheader = True',這樣我就可以重命名這些行。 – Kyrubas