[Python] Tkinter image label object is not going to the desired spot

Discussão em 'Python' iniciado por Stack, Julho 17, 2025.

  1. Stack

    Stack Membro Participativo

    I have this code with an upload image button and an image label.

    import tkinter
    from tkinter import filedialog, Label, Button
    from PIL import Image, ImageTk

    # Functions
    def upload_image():

    file_path = filedialog.askopenfilename()

    if file_path:
    img = Image.open(file_path)

    img_tk = ImageTk.PhotoImage(img)

    image_label.image = img_tk
    image_label.config(image=img_tk)



    window = tkinter.Tk()

    window.geometry("5000x3000")

    image_label = Label(window, width=2500, height=1000)
    image_label.grid(column=2,row=2)

    upload_button = Button(window, text='Upload Image', command=upload_image)
    upload_button.grid(column=1,row=1, padx=60, pady=60)


    window.mainloop()


    Now I expected the image and the upload button be pretty close, but the image label is on the other side of the app. [​IMG]

    If I add a bigger image then the whole screen gets covered by it

    I thought by defining a width and height for the image label, since I am new to Tkinter and don't know that much, I thought I would avoid big images being too big and small images being too small. My desired output is both of them to be side by side.

    Continue reading...

Compartilhe esta Página