title: Tkinter bind callback to activating a window
body: <p>I'm writing a Tkinter application in Python 3 and I've created a custom Title Bar (the bar at the top of every Windows application with the application name, close button etc.). The way I achieved this was to create an invisible window (we'll call this window <code>test</code>) that controls the main application window's behavior (which we'll call <code>Main App</code>). Below is a piece of test code that illustrates this:</p>
  
  <pre><code>from tkinter import Tk, Toplevel
  from tkinter.ttk import Button, Label, Frame, Style
  
  
  class NewRoot(Tk):
      def __init__(self):
          Tk.__init__(self)
          self.attributes('-alpha', 1.0)  # This is normally set to 0.0
  
  
  class MyMain(Toplevel):
      def __init__(self, master):
          Toplevel.__init__(self, master)
          self.overrideredirect(1)
          self.geometry('750x650+400+600')
  
          self.style = Style()
  
          self.style.configure('TTitleBar.Label',
                               width=8,
                               relief='flat',
                               foreground='red',
                               background='red',
                               anchor='center',
                               borderwidth=-1)
  
          self.style.configure('TMainWindow.Label',
                               width=8,
                               relief='flat',
                               background='blue',
                               anchor='center',
                               borderwidth=-1)
  
          self.tk_setPalette(background='green')
  
          self.x_win = None
          self.y_win = None
          self.start_x = None
          self.start_y = None
  
          # make a frame for the title bar
          title_bar = Frame(self, style='TTitleBar.Label')
          title_bar.grid(row=0, column=0, sticky='wn')
  
          label = Label(title_bar, text='Main App', style='TMainWindow.Label')
          label.grid(row=0, column=0, padx=(4, 2), pady=(4, 0), sticky='nw')
  
          minimize_button = Button(title_bar, text='MIN', command=self.minimize_window,
                                   style='TMainWindow.Label', takefocus=False)
          minimize_button.grid(row=0, column=2, padx=(563.5, 0), sticky='nw')
  
          maximise_button = Button(title_bar, text='MAX', command=self.maximize_window,
                                   style='TMainWindow.Label', takefocus=False)
          maximise_button.grid(row=0, column=3, pady=(1.4, 0), sticky='nw')
  
          close_button = Button(title_bar, text='CLOSE', command=self.close_window,
                                style='TMainWindow.Label', takefocus=False)
          close_button.grid(row=0, column=4, sticky='nw')
  
          window = Frame(self)
          window.grid(row=1, column=0, sticky='ne')
  
          # bind title bar motion to the move window function
          title_bar.bind('&lt;B1-Motion&gt;', self.move_window)
          title_bar.bind('&lt;Button-1&gt;', self.get_pos)
          self.master.bind("&lt;Map&gt;", self.on_root_deiconify)
          self.master.bind("&lt;Unmap&gt;", self.on_root_iconify)
  
          self.mainloop()
  
      def minimize_window(self):
          self.master.iconify()
  
      def maximize_window(self):
          pass
  
      def close_window(self):
          self.master.destroy()
  
      def on_root_iconify(self, event):
          # print('unmap')
          self.withdraw()
  
      def on_root_deiconify(self, event):
          # print('map')
          self.deiconify()
  
      def get_pos(self, event):
          self.x_win = self.winfo_x()
          self.y_win = self.winfo_y()
          self.start_x = event.x_root
          self.start_y = event.y_root
          self.y_win = self.y_win - self.start_y
          self.x_win = self.x_win - self.start_x
  
      def move_window(self, event):
          # print('+{0}+{1}'.format(event.x_root, event.y_root))
          self.geometry('+{0}+{1}'.format(event.x_root + self.x_win, event.y_root + self.y_win))
  
          self.start_x = event.x_root
          self.start_y = event.y_root
  
  
  if __name__ == '__main__':
  
      root = NewRoot()
      root.title('test')
      app = MyMain(root)
  </code></pre>
  
  <p>In the code above, whenever the <code>test</code> window is minimized, the <code>Main App</code> window is also minimized, which works as intended.</p>
  
  <p>The problem is that whenever the <code>test</code> window  is made active, the <code>Main App</code> window doesn't become active also. For example, if another app covers <code>Main App</code> but <code>test</code> is not minimized, I need to click on the <code>test</code> icon in the Windows Task Bar three times for it to appear.</p>
  
  <p>I was wondering if there is a way to fix this using something like: </p>
  
  <p><code>self.master.bind(&lt;some_command&gt;, self.some_other_command)</code></p>
  
  <p>However, I can't find a comprehensive list of <code>bind</code> commands anywhere.
  Is this a good way of going about this, or is there something else I should be doing?</p>
  
  <p>Also, I noticed that using <code>self.overrideredirect(1)</code> causes the shadows made by the windows to disappear, which causes overlapping windows in my application to 'merge together', since the background colors are the same. Is there a way to add the shadows back?</p>
  
  <p>Thank you in advance.</p>