我想给Tkinter.PanedWindow
sash添加一个好的句柄。为此,我在窗格旁边使用一个自定义夹点图像place
创建一个Label
。示例:
from Tkinter import *
root = Tk()
pw = PanedWindow(root, orient=HORIZONTAL)
l1 = Listbox(pw)
pw.add(l1)
l2 = Listbox(pw)
pw.add(l2)
pw.pack(fill=BOTH, expand=1)
gripimg = PhotoImage(data="R0lGODlhBAAvAPEAALetnfXz7wAAAAAAACH5BAEAAAIALAAAAAAEAC8AAAIjRBwZwmKomjsqyVdXw/XSvn1RCFlk5pUaw42saL5qip6gnBUAOw==")
griplabel = Label(pw, image=gripimg)
griplabel.place(relx=1, rely=0.5, anchor=W, in_=l1)
root.mainloop()
看起来不错。但是现在标签与窗扇重叠,窃取鼠标事件,我不能通过拖动标签来调整PanedWindow的大小。如何使griplabel
忽略鼠标事件并将它们全部重定向到PanedWindow窗口窗口?你知道吗
我试过bindtags,但是:
griplabel.bindtags(pw.bindtags())
似乎什么都不做,即我仍然无法拖动标签来调整PanedWindow的大小。你知道吗
或者有没有更好的方法为PanedWindow创建自定义句柄?你知道吗
在#tcl freenode channel的帮助下,我想到了这个:
两个
griplabel.bind(...)
调用将mousedown+mousemove事件从Label转发到PanedWindow,调整x和y坐标。这两件事足以让窗扇动起来。你知道吗griplabel鼠标“cursor”被设置为
sb_h_double_arrow
,因为根据the Tk documentation,默认情况下,这是sash使用的光标PanedWindow:它也是cursor names recognized by Tk on all platforms之一。你知道吗
TCL wiki mentions另一种设置自定义窗扇把手条的方法,使用
ttk.PanedWindow
和自定义ttk.Style
布局:但它看起来和工作原理不同。从本质上讲,它用平铺图像替换
ttk.PanedWindow
的背景,平铺图像保持静态,窗框变成在其上滑动的视口。这看起来很不寻常,但还是有人会喜欢的。你知道吗相关问题 更多 >
编程相关推荐