Unable to resize image using tkinter

I am trying to create a tkinter project in python 2.7 where the user can resize the window and everything inside the window will scale. This means that the canvas, shapes on the canvas and, most importantly, PhotoImages will be scaled using the window. My problem is life for me, I cannot resize my images correctly. I know that for this purpose subsample and zoom exist, but above all

 plantImage = PhotoImage(file="images/Arable_Cell.gif") plantImage.subsample(2, 2) canvas.create_image(0, 0, anchor=NW, image=plantImage) 

Does not make noticeable changes in the image size of 50x50 pixels, as well as to increase (2, 2). It is important to note that I know that PIL exists, but for the purposes of this project I cannot load additional libraries. So what am I doing wrong?

+4
source share
1 answer

According to the docs ,

subselect (self, x, y = ``)

Return a new PhotoImage based on the same as this widget, but use only every Xth or Yth pixel.

those. subsample does not change the image, it creates a new one, so try this instead:

 originalPlantImage = PhotoImage(file="images/Arable_Cell.gif") displayPlantImage = originalPlantImage.subsample(2, 2) canvas.create_image(0, 0, anchor=NW, image=displayPlantImage) 
+7
source

Source: https://habr.com/ru/post/1497814/


All Articles