Image covering buttons even though the buttons are registered after

Question:

I’m trying to make a resize function so that when you press the button everything changes to a new screen size, if I remove the image the buttons appear, but as soon as I add the image no buttons are registered. the code for the placing also does execute.
(I know the code is bad this is a personal project and I don’t need it to be perfect)

def resize_all():
    global allbtns, img, panel
    for i in allbtns:
        i.place_forget()

    img = Pimage.open(f"{pathlib.Path(__file__).parent.absolute()}/image.png")
    img = img.resize((WIDTH, HEIGHT))
    img = ImageTk.PhotoImage(img)
    panel = tkr.Label(app, image = img)
    panel.place(x = 0, y = 0)
 
    counter.place(x=round(WIDTH*.729), y=round(HEIGHT*.444))
    startbtn.place(x=round(WIDTH*.833), y=round(HEIGHT*.611))
    stopbtn.place(x=round(WIDTH*.881), y=round(HEIGHT*.611))
    savepbtn.place(x=round(WIDTH*.833), y=round(HEIGHT*.644))
    respbtn.place(x=round(WIDTH*.881), y=round(HEIGHT*.644))
    savedval.place(x=round(WIDTH*.847), y=round(HEIGHT*.68))
    infobtnp.place(x=round(WIDTH*.379), y=round(HEIGHT*.333))
    infobtnr.place(x=round(WIDTH*.407), y=round(HEIGHT*.333))
    comentsbtnp.place(x=round(WIDTH*.392), y=round(HEIGHT*.526))
    comentsbtnr.place(x=round(WIDTH*.42), y=round(HEIGHT*.526))
    folosbtnp.place(x=round(WIDTH*.236), y=round(HEIGHT*.7))
    folosbtnr.place(x=round(WIDTH*.263), y=round(HEIGHT*.7))
    drops.place(x=round(WIDTH*.784), y=round(HEIGHT*.622))
    dropm.place(x=round(WIDTH*.746), y=round(HEIGHT*.622))

I already tried changing the order of the registering but it still doesn’t work.
If you need the whole code leave a comment and I’ll send it.

Asked By: dmcpacks

||

Answers:

The problem appears to be that the image is covering the buttons. You can try lowering the image to the bottom of the stacking order with something like this:

panel.lower()

Arguably, a better solution is to create the image label at the same time you create the other widgets, and create it first so that that is lowest in the stacking order. Then, inside resize_all you can just give the existing label a different image:

def resize_all():
    ...
    img = Pimage.open(f"{pathlib.Path(__file__).parent.absolute()}/image.png")
    img = img.resize((WIDTH, HEIGHT))
    img = ImageTk.PhotoImage(img)
    self.panel.configure(image=img)
    ...
Answered By: Bryan Oakley
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.