寻找一种方法来获得一个事件,当一个改变一个列的宽度,例如。我希望在用户交互更改列宽(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()谢谢你的帮助
发布于 2021-02-27 23:16:06
找到了使用link 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)https://stackoverflow.com/questions/66389950
复制相似问题