[Python] I cannot make a background using label in tkinter

Discussão em 'Python' iniciado por Stack, Março 10, 2025.

  1. Stack

    Stack Membro Participativo

    Can't wrap my head around this problem. So I am creating a simple app - just with a text box, user input, and a button. I want to make it fancy and create a background using labels. But the thing is that it works, but the image I am using is just stretched in width. It is not background, because lower is all of my widgets. The picture of how it looks like

    def background_manage(self):
    self.bg_image = Image.open(r"here is my path")
    #we get the current window razmer
    win_width=self.master.winfo_screenwidth()
    win_height=self.master.winfo_screenheight()
    self.bg_image = self.bg_image.resize((win_width, win_height), Image.LANCZOS)
    self.background_image=ImageTk.PhotoImage(self.bg_image)
    self.label = tk.Label(self, image=self.background_image)
    self.label.image = self.background_image
    self.label.place(x=0,y=0,relwidth=1, relheight=1)
    self.label.lower()


    So I tried making all the cooking with label inside init. still didn't work. I cannot understand what am I doing wrong. I am new to Tkinter, so I probably missed something ALso I tried creating a function that gets my app width and height and then applies it to the background. But I probably did it wrong. Even if I set the right size manually. I think I am messing up with the widgets layout.

    Continue reading...

Compartilhe esta Página