0

I hope you're having a good day. Let me show you the code first

from tkinter import *
from PIL import ImageTk, Image

with open(image_path, 'rb') as f:
    img = f.read()

root=Tk()
image = ImageTk.PhotoImage(data=img)
my_label = Label(image=image)
my_label.pack()
root.mainloop()

As you can see, I am reading an image file in 'rb' mode and then using the lines of codes to display the image in a tkinter window. However, in this method, I just cannot resize the image(I can crop the image, but I need to resize it). Now, my question is, how do I change the size the image?

PS: I'm an extreme noob. Please pardon me if this question is too stupid

AMC
  • 2,642
  • 7
  • 13
  • 35
ashab999
  • 13
  • 4
  • 1
    Does this answer your question? [Python3 tkinter set image size](https://stackoverflow.com/questions/44977163/python3-tkinter-set-image-size) – Matthias Fripp Jul 09 '20 at 18:06
  • 1
    is there a specific reason you're using `with open` ? or is it simply, cuz if it is then you cud jus use `Image.open()` which is by PIL itself and helps in resizing image too – Delrius Euphoria Jul 09 '20 at 18:20
  • As an aside, `import *` is generally bad practice. – AMC Jul 10 '20 at 02:59
  • @MatthiasFripp, I'm sorry, but no :( – ashab999 Jul 10 '20 at 04:53
  • @CoolCloud I want to read the image in 'rb' from a directory, and then display it in a tkinter window after resizing the image. I can't find anything out of PIL to help me resize it after reading the image file. – ashab999 Jul 10 '20 at 04:56
  • im not sure i knw hw to do it, but if u want to jus read a normal file, we can do using `Image.open()` – Delrius Euphoria Jul 10 '20 at 06:24

0 Answers0