title: tkinter : How to create a custom widget having a listbox that can appear and disappear over another widget without moving the other widget?
body: <p>I had earlier posted a question on "<a href="https://stackoverflow.com/questions/41811921/tkinter-how-to-create-a-listbox-that-can-appear-and-disappear-over-another-wid">how to create a listbox that can appear and disappear over another widget without moving the other widget?</a>". Bryan Oakley answered my question and provided very helpful explanation and pointers.</p>
  
  <p>Presently, I am looking at the next level scenario to my previous  question. That is, I want to customize a new widget that consist of a label and a listbox. It's listbox should appear and disappear in front of surrounding widgets when the new widget is clicked by a mouse pointer and the surrounding widget's position must not change. I have tried to apply what I learned previously and modified my earlier code to try to achieve my goal. My code is shown below. </p>
  
  <p>The problem I am having is the listbox of mythe custom widget only appear within the frame of the custom widget (green) even though I used the <code>.place</code> layout manager. Bryan previously wrote that </p>
  
  <blockquote>
    <p><code>place</code> doesn't affect other children of the same parent. </p>
  </blockquote>
  
  <p>In this case, how should I restructure my code and widgets such that the listbox in a custom widget, when it appears, would appear in front of neighboring widgets of the custom widget? In my code, I would like the listbox to appear in front of <code>self.label2</code>, defined in <code>class 'App'</code>, when <code>self.newwidget</code> is clicked.  </p>
  
  <pre><code>#!/usr/bin/python3
  # -*- coding: utf-8 -*-
  
  try:
      import tkinter as tk # Python 3 tkinter modules
  except ImportError:
      import Tkinter as tk # Python 2 tkinter modules
  
  class NewWidget(tk.Frame):
      def __init__(self, parent, lb_values):
          tk.Frame.__init__(self, parent, background='green', borderwidth=10,
                            pady=30)
          # Initialise local variable
          self.toggle = True
          # Create widgets of NewWidget
          self.label1 = tk.Label(
              self, text='Click me to see Names of Famous Folks')
          self.lbframe = tk.Frame(self, background='orange', borderwidth=10)
          self.lbframe.list= tk.Listbox(self.lbframe, height=5, width=10)
          # Put values into listbox
          for item in lb_values:
              self.lbframe.list.insert(tk.END, item)
          # Manage widgets layout
          self.label1.pack(fill="both", expand=True)
          self.lbframe.list.pack(fill="both", expand=True)
          # Set widget bindding
          self.label1.bind("&lt;Button-1&gt;", self.ShowHideListbox)
  
      def ShowHideListbox(self, event):
          if self.toggle: # Show
              self.toggle=False
              self.lbframe.place(
                  in_=event.widget, x=0, rely=1, relwidth=1.0, anchor="nw")
          else: # Hide
              self.toggle=True
              self.lbframe.place_forget()
  
  
  class App(tk.Frame):
      def __init__(self, parent):
          tk.Frame.__init__(self, parent, background='pink')
  
          self.label1 = tk.Label(self, text='Welcome!')
          nlist = ['Peter', 'Scotty', 'Walter', 'Scott', 'Mary']
          self.newwidget = NewWidget(self, nlist)
          self.label2 = tk.Label(self, height=10,
                                 text='The World of Famous Folks! Revealed!',)
  
          self.label1.grid(row=0, column=0, sticky='nsew', pady=10)
          self.newwidget.grid(row=1, column=0, sticky='nsew')
          self.label2.grid(row=2, column=0, sticky='nsew')
  
          self.label2.columnconfigure(2, weight=1)
  
  
  if __name__ == '__main__':
      root = tk.Tk()
      root.geometry("300x300")
      app = App(root)
      app.pack(fill="both", expand=True)
      app.mainloop()
  </code></pre>