here2share

# Tk_image_resize_demo.py

Aug 21st, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. # Tk_image_resize_demo.py
  2.  
  3. from Tkinter import *
  4. from PIL import ImageTk, Image
  5.  
  6. root=Tk()
  7. img=Image.open("solidball.png") # http://tinyurl.com/h2sball001
  8. canvas=Canvas(root, height=200, width=200)
  9. canvas.pack(side = TOP, expand=True, fill=BOTH)
  10.  
  11. def img_resize(basewidth):
  12.     image=img
  13.     wpercent = (basewidth / float(image.size[0]))
  14.     hsize = int((float(image.size[1]) * float(wpercent)))
  15.     image = image.resize((basewidth, hsize), Image.ANTIALIAS)
  16.     photo = ImageTk.PhotoImage(image)
  17.     item4 = canvas.create_image(100, 100, image=photo)
  18.     canvas.update()
  19. #
  20. while True:
  21.     for basewidth in range(1, 400):
  22.         img_resize(basewidth)
  23. root.mainloop()
Add Comment
Please, Sign In to add comment