1

Looking for a method to get an event when one changes the width of a column Eg. I would like to have an event when the column width (A or B) is changed by user interaction. My example only binds when the full table width is changed

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()

Thanks for any help

Community
  • 1
  • 1
Vik
  • 333
  • 5
  • 14

1 Answers1

0

Found the solution with link How to bind an action to the heading of a tkinter treeview in python?

So I did:

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

and implemented:

def on_button_release_1(event):
    region = table.identify("region", event.x, event.y)
    if region == "separator":
        print(event)
Vik
  • 333
  • 5
  • 14