更改tkintertable行的名称

2024-10-02 22:33:35 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我正在tkinter中开发一个嵌入式用户可编辑表。我想给PlateLayout类一组自定义的行,而不是默认的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()

我已经看到了重命名列的屏幕截图,但还没有找到如何以编程方式实现这一点的参考。在


Tags: theimportselfappmakedeftableroot
1条回答
网友
1楼 · 发布于 2024-10-02 22:33:35

引用自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()
....

相关问题 更多 >