寻找一种在更改列宽时获取事件的方法,例如。当用户交互更改列宽(A 或 B)时,我希望有一个事件。我的示例仅在更改整个表格宽度时绑定
from ttkwidgets import Table
import tkinter as tk
def changed(event):
print(event)
root = tk.Tk()
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)
columns = ["A", "B"]
table = Table(root, columns=columns)
table.bind('<Configure>', changed)
for col in columns:
table.heading(col, text=col)
table.column(col, width=100, stretch=False)
for i in range(3):
table.insert('', 'end', iid=i,
values=(i, i) + tuple(i + 10 * j for j in range(2, 7)))
# add scrollbars
sx = tk.Scrollbar(root, orient='horizontal', command=table.xview)
sy = tk.Scrollbar(root, orient='vertical', command=table.yview)
table.configure(yscrollcommand=sy.set, xscrollcommand=sx.set)
table.grid(sticky='nesw')
sx.grid(row=1, column=0, sticky='ew')
sy.grid(row=0, column=1, sticky='ns')
root.update_idletasks()
frame = tk.Frame(root)
frame.grid()
root.geometry('400x200')
root.mainloop()
谢谢你的帮助