首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python ttkwidget表更改列宽时如何绑定事件

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

Stack Overflow用户
提问于 2021-02-27 01:00:01
回答 1查看 59关注 0票数 1

寻找一种方法来获得一个事件,当一个改变一个列的宽度,例如。我希望在用户交互更改列宽(A或B)时发生事件。我的示例仅在更改整个表格宽度时进行绑定

代码语言:javascript
复制
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()

谢谢你的帮助

EN

回答 1

Stack Overflow用户

发布于 2021-02-27 23:16:06

找到了使用link How to bind an action to the heading of a tkinter treeview in python?的解决方案

所以我就这么做了:

代码语言:javascript
复制
table.bind("<ButtonRelease-1>", on_button_release_1)

并实现了:

代码语言:javascript
复制
def on_button_release_1(event):
    region = table.identify("region", event.x, event.y)
    if region == "separator":
        print(event)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66389950

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档