Tkinter lift and lower methods with grid layout
python, tkinter
Solution
You can't lower a widget below its parent. According to the official tk docs:
If the aboveThis argument is omitted then the command raises window so that it is above all of its siblings in the stacking order (it will not be obscured by any siblings and will obscure any siblings that overlap it). If aboveThis is specified then it must be the path name of a window that is either a sibling of window or the descendant of a sibling of window. In this case the raise command will insert window into the stacking order just above aboveThis (or the ancestor of aboveThis that is a sibling of window); this could end up either raising or lowering window.
(NB. the tk `raise` command is what `lift()` actually calls at the lowest level)
To get the effect you want, make the frame and the listbox siblings, then use the `in_` parameter to pack the listboxes inside the frame:
food.grid(row=0, column=1, in_=frame)
pythons.grid(row=1, column=1, pady=10, in_=frame)
Problem
No doubt this is a newbie question. I'm using the grid layout manager in Tkinter with Python 2.7. I want a button to hide a listbox on clicking. Here's my code so far: ``` from Tkinter import * root = Tk() frame = Frame(root) pyList = ["Eric", "Terry", "Graham", "Terry", "John", "Carol?", "Michael"] arbList = ['ham', 'spam', 'eggs', 'potatos', 'tots', 'home fries'] pythons = Listbox(frame, width=10, height=5, selectmode=EXTENDED, exportselection=0) food = Listbox(frame, width=10, height=5, selectmode=EXTENDED, exportselection=0) def hider(): if pythons.selection_includes(4): food.lower() elif pythons.selection_includes(0): food.lift() b2 = Button(frame, text="Hide!", command=hider) b2.grid(row=2, column=1) food.grid(row=0, column=1) pythons.grid(row=1, column=1, pady=10) frame.grid() for python in pyList: pythons.insert('end', python) for thing in arbList: food.insert('end', thing) root.mainloop() ``` Unfortunately, monkeying around with this appears to throw an error saying I can't lift/lower my listbox above or below my frame. I've gotten this to work with the pack() manager, but not grid(). What am I missing?