How to reduce image size in python turtle graphix

Viewed 28

I loaded an image on my turtle screen and I tiried to reduce it's size using tkinter but the zoom function does not accept decimals meaning it can't reduce sizeso I will like to know if there is any way to do it. Here's what I did

from turtle import Shape, Screen, Turtle
from tkinter import PhotoImage


wn = Screen()
wn.setup(width = 700, height = 1500)
wn.bgcolor('white')
pic = PhotoImage(file = "2.gif").zoom(1.1, 1.1)
wn.addshape('pic', Shape("image", pic))

tr = Turtle("pic")
while True:
    wn.update()
1 Answers

You may use module Pillow to modify images - resize, convert colors, crop, rotate, add text and figures, etc.

It can also create PhotoImage for tkinter.
It is popular method to use jpg or other formats in tkinter.

from turtle import Shape, Screen, Turtle
from tkinter import PhotoImage
from PIL import Image, ImageTk

wn = Screen()
wn.setup(width=500, height=500)
wn.bgcolor('white')

img = Image.open("lenna.png")
#w, h = img.size
w = int(img.width*0.1)
h = int(img.height*0.1)
img = img.resize( (w, h) )
pic = ImageTk.PhotoImage(img)

wn.addshape('pic', Shape("image", pic))

tr = Turtle("pic")
#while True:
#    wn.update()
wn.mainloop()

enter image description here


Image Lenna from Wikipedia

Related