We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,756 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

To zoom an image in tkinter

Below is en2.py code-

    # The Python Imaging Library
    # $Id$
    # this demo script creates four windows containing an image and a slider.
    # drag the slider to modify the image.
    #

    from Tkinter import *
    from PIL import Image, ImageTk, ImageEnhance
    import sys

     # enhancer widget

    class Enhance(Frame):
        def __init__(self, master, name, enhancer, lo, hi):
            Frame.__init__(self, master)

            # set up the image

            self.tkim = ImageTk.PhotoImage(image.mode, image.size)
            self.enhancer = enhancer(image)
            #mid = (lo + hi)/2
            self.update('1.0') # normalize

            # image window
            Label(self, image=self.tkim).grid()

            # scale
            s = Scale(self, label=name, orient=HORIZONTAL,
                      from_=lo, to=hi, resolution=0.01,
                      command=self.update)
            #if image == "ip_img.jpg" or image == "not_img.jpg":
             #   s.config(state=DISABLED)
            s.set(self.value)
            s.grid(row=0,column=0)

        def update(self, value):
            self.value = eval(value)
            tkim.paste(self.enhancer.enhance(self.value))
  • Now in another code below, I have to write the code that resizes en2.image or another ImageTk.PhotoImage instance that contains a copy of en2.image.

    ####zoom in photoimage instance of en2.image code here

    Label(top, image=en2.tkim).grid(row=0, column=10, columnspan=20, rowspan=20,padx=10, sticky=W+E+N+S)

    im = Image.open("zoomin.jpg")
    image = im.resize((80,30),Image.ANTIALIAS)
    photo = ImageTk.PhotoImage(image)
    b=Button(root, image=photo,command=zoomin)
    b.grid(row=5,column=0)

    root.mainloop()

    I've googled and some documents show that there is a zoom method that can be used with photoimage instance but it gives attribute error on the interpreter.
    I tried to change the height and width explicitly using en2.image.height=900 (say), but even thats not working, it does not raise an error, but at the same time, it does not alter the height.

Please tell me a way so that I can resize en2.image.

2
Contributors
1
Reply
1 Day
Discussion Span
10 Months Ago
Last Updated
2
Views
vy_007
Newbie Poster
9 posts since Jul 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
pyTony
pyMod
Moderator
6,301 posts since Apr 2010
Reputation Points: 879
Solved Threads: 986
Skill Endorsements: 26

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0735 seconds using 2.65MB