Over the past several years I’ve been using a full-featured combobox widget that I made by stitching together other Tkinter widgets. (Because I like it better than ttk.Combobox.) For the dropdown I’ve always used a Toplevel widget since it overlaps other widgets instead of pushing them aside. I’ve never been able to get the place geometry manager to work as the dropdown, it won’t overlap the other widgets. I know that some people say never use place()
for anything anyway, but I just have to satisfy my curiosity as to whether it would be easier to use a place
d Frame instead of using a borderless Toplevel window.
But I can’t get the place
d Frame to overlap at all, so can someone tell me what’s wrong with this simple sample code, why doesn’t the dropdown
overlap other widgets? As soon as its rely
is set to 1, it becomes invisible, covered by the other widgets.
def unplace():
dropdown.place_forget()
def show(evt=None):
dropdown.lift()
dropdown.place(relx=0, rely=0.3, anchor='nw', relwidth=1.0)#rely=1,
# dropdown.place(relx=0, rely=1, anchor='nw', relwidth=1.0)
dropdown_item.grid(sticky="ew")
root = tk.Tk()
root.geometry("400x400+600+300")
root.config(bg="red")
root.rowconfigure(0, weight=1)
root.columnconfigure(0, weight=1)
frm = tk.Frame(root, bg="blue")
frm.grid(sticky="news")
ent = tk.Entry(frm)
ent.grid()
ent.bind("<Button-1>", show)
dropdown = tk.Frame(ent, bg="tan")
dropdown_item = tk.Button(
dropdown, bg="steelblue", width=12, command=unplace, text="item")
# If these labels are commented, `dropdown` still won't overlap.
c = tk.Label(frm, text="Overlap Me")
c.grid()
d = tk.Label(frm, text="Overlap Me")
d.grid()
e = tk.Label(frm, text="Overlap Me")
e.grid()
f = tk.Label(frm, text="Overlap Me")
f.grid()
show()
root.mainloop()