Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8217901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:36:12+00:00 2026-06-07T12:36:12+00:00

In the following block, clicking on a_frame triggers the event handler on_frame_click , but

  • 0

In the following block, clicking on a_frame triggers the event handler on_frame_click, but clicking on a_label which is a child of a_frame does not. Is there a way to force a_frame to trap and handle events which originated on it’s children (preferably with out having to add handlers to the children directly)? I am using Python 3.2.3.

import tkinter

def on_frame_click(e):
    print("frame clicked")

tk = tkinter.Tk()
a_frame = tkinter.Frame(tk, bg="red", padx=20, pady=20)
a_label = tkinter.Label(a_frame, text="A Label")
a_frame.pack()
a_label.pack()
tk.protocol("WM_DELETE_WINDOW", tk.destroy)
a_frame.bind("<Button>", on_frame_click)
tk.mainloop()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T12:36:13+00:00Added an answer on June 7, 2026 at 12:36 pm

    Yes, you can do what you want, but it requires a bit of work. It’s not that it’s not supported, it’s just that it’s actually quite rare to need something like this so it’s not the default behavior.

    TL;DR – research “tkinter bind tags”

    The Tkinter event model includes the notion of “bind tags“. This is a list of tags associated with each widget. When an event is received on a widget, each bind tag is checked to see if it has a binding for the event. If so, the handler is called. If not, it continues on. If a handler returns “break”, the chain is broken and no more tags are considered.

    By default, the bind tags for a widget are the widget itself, the widget class, the tag for the toplevel window the widget is in, and finally the special tag “all”. However, you can put any tags you want in there, and you can change the order.

    The practical upshot of all this? You can add your own unique tag to every widget, then add a single binding to that tag that will be processed by all widgets. Here’s an example, using your code as a starting point (I added a button widget, to show this isn’t something special just for frames and labels):

    import Tkinter as tkinter
    
    def on_frame_click(e):
        print("frame clicked")
    
    def retag(tag, *args):
        '''Add the given tag as the first bindtag for every widget passed in'''
        for widget in args:
            widget.bindtags((tag,) + widget.bindtags())
    
    tk = tkinter.Tk()
    a_frame = tkinter.Frame(tk, bg="red", padx=20, pady=20)
    a_label = tkinter.Label(a_frame, text="A Label")
    a_button = tkinter.Button(a_frame, text="click me!")
    a_frame.pack()
    a_label.pack()
    a_button.pack()
    tk.protocol("WM_DELETE_WINDOW", tk.destroy)
    retag("special", a_frame, a_label, a_button)
    tk.bind_class("special", "<Button>", on_frame_click)
    tk.mainloop()
    

    For more on bindtags, you might be interested in my answer to the question How to bind self events in Tkinter Text widget after it will binded by Text widget?. The answer addresses a different question than the one here, but it shows another example of using bind tags to solve real world problems.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Short and sweet: Why does the following block of Objective-C code not produce a
I've got the following block definition, which outputs the block of my/type just fine:
i have the following block of code: $(#contact_container form, #contact_details form).live( submit, function(event) {
I have the following block of code which works fine; var boughtItemsToday = (from
Is there a way to improve the following block of if statements? I was
I have added the following block of code to my WP7 app and not
The following block of code: ans = 'x' while ans not in ['Y','y','N','n']: ans
I have the following block: <a href=mailto:a@b.com>Send me a mail!</a> There's plenty of styles
I have the following block in my JSP, which converts from ENUM values {CREATE,
In the following block of code, does VB.NET gracefully exit the With block if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.