通过其他小部件点击事件?

时间:2014-07-31 06:42:39

标签: python tkinter

我有一个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')

1 个答案:

答案 0 :(得分:0)

titlebar.bind_all('<Button-1>', drag_window) 

可能是您正在寻找的,来自: tkinter clicks on child do not propagate to parent

尝试2本地化点击:

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

并更改&#39; bind_all&#39;回到&#39; bind&#39;。

相关问题