tkintertable:连续添加按钮?

时间:2019-02-24 16:51:56

标签: python button tkinter

是否可以在tkintertable的单元格中添加(tkinter)按钮? 例如

from tkintertable import TableCanvas, TableModel
self.contenitore = ttk.Frame(root) 
data = {'rec1': {'col1': 99.88, 'col2': 108.79, 'label': 'rec1'},
    'rec2': {'col1': 99.88, 'col2': 321.79, 'label': 'rec3'},
    'rec3': {'col1': 29.88, 'col2': 408.79, 'label': 'rec2'}
    }
    tabella = TableCanvas(self.contenitore, data=data,editable=False)

我可以为每行添加一个带有按钮的列吗?

1 个答案:

答案 0 :(得分:3)

是的,但是很老套。 TableCanvas是tkinter Canvas的一种,因此您可以使用所有tkinter Canvas方法。要将{Button}之类的小部件添加到Canvas,请使用create_window()方法。

tabella.update()
x1,y1,x2,y2 = tabella.getCellCoords(1,1) # place the button at cell 1, 1
btn = tk.Button(tabella, text="Hello")
tabella.create_window(((x1+x2)//2, (y1+y2)//2), window=btn)

您可以并且应该使用x1,y1,x2,y2来调整按钮的大小,使其完全适合单元格。