[Python] Resize photo in frame with grid

Discussão em 'Python' iniciado por Stack, Agosto 29, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to resize a photo into a grid. I made a frame with mainframe patent to pack the photo without using grip and can resize it with event.width and event.height. The program compiles without errors but without showing any object.

    #function to resize image when window size change
    def boardResize(event):
    boardlabel = event.widget
    _imageWidth = event.width
    _imageHeight = event.height
    global sizeChangedBoardImg, sizeChangedBoardPho
    sizeChangedBoardImg= dynamicChangeBoardImg.resize((_imageWidth,_imageHeight))
    sizeChangedBoardPho= ImageTk.PhotoImage(sizeChangedBoardImg)
    boardlabel.config(image = sizeChangedBoardPho)
    # avoid garbage collector
    boardlabel.image = sizeChangedBoardPho


    # Label for image
    boardImage = Image.open('chargerController_bb.png')
    imageWidth = int(rootSizerWidth * 0.4)
    Image height = int(rootSizerHeight * 0.4)
    resizedboardImage = boardImage.copy().resize((imageWidth,imageHeight))
    dynamicChangeBoardImg = boardImage.copy()
    photoBoard = ImageTk.PhotoImage(resizedboardImage)
    board label = ttk.Label(photoFrame,image = Photo board)

    boardlabel.bind('<Configure>',boardResize)
    boardlabel.pack()
    photoFrame.grid(column=5,row=3, rowspan = 10, sticky=(W,E,N,S))

    Continue reading...

Compartilhe esta Página