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 with it. This means the canvas, the shapes in the canvas and most importantly the PhotoImages will scale with the window. My problem, is for the life of me I cannot get my images to resize properly.
I know that subsample
and zoom
exist for this purpose, but first of all
plantImage = PhotoImage(file="images/Arable_Cell.gif")
plantImage.subsample(2, 2)
canvas.create_image(0, 0, anchor=NW, image=plantImage)
Makes no noticeable change in a 50x50 pixel image and same for zoom(2, 2). It is important to note I know PIL exists but for the purposes of this project I cannot download any extra libraries. So what am I doing wrong?
According to the docs,
subsample(self, x, y='')
Return a new PhotoImage based on the same image as this widget but use only every Xth or Yth pixel.
I.e. subsample
doesn't modify 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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With