1
class SomeClass(tk.Frame):

def __init__(self, root):
    tk.Frame.__init__(self, root, bg="#ffffff")

    self.label_image = tk.Label(self, bg ="#ffffff")
    self.label_image.pack(anchor=tk.CENTER, fill=tk.X, padx=20, pady=10)
    self.label_image.bind('<Configure>', self._resize_image)


def _resize_image(self, event):
    print("resize_image")
    f_w, f_h = self.winfo_width(), self.winfo_height() - 50
    i_w, i_h = self.img_copy.size
    width = 1
    height = 1

    if f_w/f_h > i_w/i_h:
        height = f_h
        width = int(i_w * f_h/i_h)
    else:
        width =  f_w
        height = int(i_h * f_w/i_w)

    self.image = self.img_copy.resize((width, height), PIL.Image.ANTIALIAS)
    loading_image = ImageTk.PhotoImage(self.image)
    self.label_image.configure(image=loading_image)
    self.label_image.image = loading_image

MacOSX. When you stretch the screen, the code works fine, but if you make an application on a full screen and open a picture, it will slowly increase proportionally. On Ubuntu, the picture remains small and does not increase at all.

In terminal will see: resize_image resize_image resize_image resize_image resize_image...

  • Possible duplicate of [How do I resize an image using PIL and maintain its aspect ratio?](https://stackoverflow.com/questions/273946/how-do-i-resize-an-image-using-pil-and-maintain-its-aspect-ratio) – stovfl Nov 26 '18 at 11:04

0 Answers0