Answer the question
In order to leave comments, you need to log in
Image resizing in Tkinter, Python?
I'm creating a simple Tkinter game, I have an image, but I need the image to span 1 horizontally and 0.9 vertically without cropping the image. By any means, the image is only trimmed, not reduced. It is necessary that the size of the image is not set manually, but the exact amount is 0.9 from the screen vertically (it occupies the entire white background)
Answer the question
In order to leave comments, you need to log in
get canvas dimensions
cnv = tk.Cnavas(...) # создали канву
.....
w = cnv['width']
h = cnv['height']
from PIL import Image
......
image = Image.open(....) # представили изображение в виде объекта PIL.Image
scaled_image = image.resize((w,h), Image.ANTIALIAS) # растянули/сжали
from PIL import ImageTk
image4canvas = ImageTk.PhotoImage(scaled_image) # представили изображение в виде объекта PIL,
# с которым умеет работать канва
cnv.create_image(0, 0, anchor=tk.NW, image=image4canvas) # нарисовали изображение на канве
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question