OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Tkinter place geometry manager not overlapping

  • Thread starter Thread starter Luther
  • Start date Start date
L

Luther

Guest
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 placed Frame instead of using a borderless Toplevel window.

But I can't get the placed 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.

Code:
import tkinter as tk

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()
<p>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 <code>place()</code> for anything anyway, but I just have to satisfy my curiosity as to whether it would be easier to use a <code>place</code>d Frame instead of using a borderless Toplevel window.</p>
<p>But I can't get the <code>place</code>d Frame to overlap at all, so can someone tell me what's wrong with this simple sample code, why doesn't the <code>dropdown</code> overlap other widgets? As soon as its <code>rely</code> is set to 1, it becomes invisible, covered by the other widgets.</p>
<pre><code>import tkinter as tk

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()
</code></pre>
 

Latest posts

A
Replies
0
Views
1
Ashrik Ahamed
A
A
Replies
0
Views
1
Ashrik Ahamed
A

Online statistics

Members online
0
Guests online
4
Total visitors
4
Top