繁体   English   中英

通过另一个窗口小部件单击事件?

[英]Click event through another widget?

我有一个Frame(),其中包含另一个Label()。

Frame()有一个绑定事件,在拖动时会移动它。 问题是标签在“途中”,因此在标签上单击时,它不会在小部件下方拾取事件。

有没有办法制作Label(),因此它的点击将被忽略并一直通过?

对不起,麻烦的问题。 这是一些示例代码:

titlebar = Frame(app, height=20, background='#333333')
titlebar.pack(side='top', fill=X, padx=4, pady=4)
titlebar.bind('<Button-1>', drag_window) # This event should also be triggered through label widget

titlebar_label = Label(titlebar, text='Node Handler',
                   background='#333333', foreground='#ffffff')
titlebar_label.pack(side='left')
titlebar.bind_all('<Button-1>', drag_window) 

可能是您要查找的内容,来自: tkinter对孩子的点击不会传播给父母

尝试2定位点击目标:

titlebar_label.bindtags(('.titlebar_label','Label', 'clickthru','.','all'))
titlebar.bind_class('clickthru', '<Button-1>', drag_window)

并将“ bind_all”更改回“ bind”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM