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

  • Home
  • SEARCH
  • 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 8775793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:53:38+00:00 2026-06-13T18:53:38+00:00

I have problems when destroying a window that has a bind to an external

  • 0

I have problems when destroying a window that has a bind to an external widget.

For example, I have one root window, and many different subwindows (in the code is the same one to make it simple).

When I open a subwindow from the root.
It creates a window and binds to a signal from the root window.
All the subwindows will bind to this same signal but to a different callbacks (one for each subwindow).

Then when I destroy this subwindow (click X in the top corner) the bind still alive, this means the subwindow still alive.

The question is:
How do I destroy the subwindow with its bind, leaving the other callbacks alive?

In the subwindow _destroy method, I have tried

root.unbind("<<EverybodyDoSomething>>", self.bind1) 

but I get an error

TclError: can’t delete Tcl command

And if I use

root.unbind("<<EverybodyDoSomething>>")

All the callbacks assosiated with the signal get unbinded.

import Tkinter as Tk

root = Tk.Tk()
i_window = 0

def generate_dosomething_signal():
    root.event_generate('<<EverybodyDoSomething>>', when = 'tail')

def subwindow():
    SubWindow()

class SubWindow(Tk.Tk):
    def __init__(self):
        global i_window
        Tk.Tk.__init__(self)
        self.i = str(i_window)
        i_window += 1
        l = Tk.Label(master=self, text='This is s Sub Window %s!!!!'%self.i)
        l.pack()
        self.bind1 = root.bind('<<EverybodyDoSomething>>', 
                               self.callback_from_sub_window, '+')

        self.bind('<Destroy>', self._destroy)

    def _destroy(self, *args):
#        root.unbind('<<EverybodyDoSomething>>', self.bind1)
#        root.unbind('<<EverybodyDoSomething>>')
        pass

    def callback_from_sub_window(self, *args):
        print 'callback from Sub Window ' + self.i

bStartWindow = Tk.Button(master=root, text='Start Sub Window', command=subwindow)
bStartWindow.pack()

bDoSomethingEverywhere = Tk.Button(master=root, text='Do something everywhere', 
                                   command = generate_dosomething_signal)
bDoSomethingEverywhere.pack()

root.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-13T18:53:40+00:00Added an answer on June 13, 2026 at 6:53 pm

    What you say isn’t the normal behavior of Tkinter. Normally when you destroy a widget, all of its children widgets get destroyed too. When they get destroyed, their bindings go with them.

    Most likely, the root of your problem lies in the fact you are creating more than one instance of the root widget. You simply cannot do this. A Tkinter application must have exactly one instance of Tk, and exactly one instance of a running mainloop.

    If you want more than one top level window, create instances of Toplevel for your second and subsequent windows.

    Also, you should not be using bind(...,"+") to accomplish this task. As you’ve discovered, there is no way to remove such a binding. You can completely remove all bindings to <<EverybodyDoSomething>>, but you can’t remove only one part that was added with bind(..."+").

    What you need to do instead is have a single binding that calls a single function. This function can then iterate over a list of toplevel windows, sending the event to each window. You can simply skip any windows that no longer exist. You can either use introspection to get a list of toplevel windows, or you can manually maintain this list by appending a window reference each time your code creates one.

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

Sidebar

Related Questions

I have problems with dealing with widows within a multicols environment, that is, I
I have problems getting some of my views aligned in a relative layout that
We have small class, that has a related class class Car has_one :engine, :dependent
I have a form with a table that has two input boxes, a select
In my current Backbone app, I have no problems creating or destroying models. The
i have problems with a really basic thing. setting properties after instantiation a UIViewController-
I have problems with creating a simple Group-Box-Control via CreateWindowEx. The font-size/-style of its
I have problems with CSS. The table is creating white border and I do
I have problems dealing with ProGuard and Android. I searched on the web for
I have problems trying to load png file into my application. It seems to

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.