Python ttkwidget 表如何在更改列宽时绑定事件

问题描述

寻找一种在改变列宽时获取事件的方法 例如。当用户交互更改列宽(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()

感谢您的帮助

解决方法

通过链接找到解决方案 How to bind an action to the heading of a tkinter treeview in python?

所以我做到了:

table.bind("<ButtonRelease-1>",on_button_release_1)

并实施:

def on_button_release_1(event):
    region = table.identify("region",event.x,event.y)
    if region == "separator":
        print(event)