Python Forum
Get the parent label of a ImageTk.PhotoImage
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get the parent label of a ImageTk.PhotoImage
#1
Hi,
i have five labels with a Photo in a frame:
            for entry in dir:
                file = self.file_path + "\\" + entry
                if os.path.isfile(file):
                    try:
                        label = tk.Label(self.inner, text=location_date_str + entry)
                        label.pack(side="top", anchor=tk.NW, pady=(10, 0))
                        image = ImageTk.PhotoImage(Image.open(file))
                        image_label = tk.Label(self.inner, image=image)
                        self.photos.insert(0, image) # to prevent garbage collector from remove...
                        image_label.pack(side="top", anchor=tk.NW)
                    except:
                        tk.messagebox.showinfo(title="Exception", message=traceback.format_exc())
Now to zoom in and out i guess that i can't just change the image, because the new image would not have the same reference as the old one and therefore the label wouldn't get the new but hold the old one.
So i tried to get the parent label of the image to set the new image onto like this:

    def zoom_in(self, event=None):
        print("zoom in")
        for image in self.photos:
            # get the parent (label) of the image
            label = image.winfo_parent()
            # get a zoomed image
            image = image._PhotoImage__photo.zoom(2)
            label.config(image=image)
Error message: 'PhotoImage' object has no attribute 'winfo_parent'

So:
- Is this function not impelemented, why?
- how can i get the parent of the image?
- is there another way to zoom such images?
Reply


Messages In This Thread
Get the parent label of a ImageTk.PhotoImage - by delphinis - Aug-02-2020, 10:35 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  question on tkinter canvas PhotoImage gr3yali3n 1 2,155 Sep-05-2020, 12:18 PM
Last Post: Larz60+
  Gif with PhotoImage Friend 3 5,321 Jul-23-2019, 10:23 PM
Last Post: Friend
  Move PhotoImage dan789 2 2,720 Dec-19-2018, 06:00 PM
Last Post: dan789
  [Tkinter] PhotoImage and Jpeg images. rozen 3 4,604 Jan-07-2018, 08:34 AM
Last Post: Gribouillis
  Ho can I get the first parent of a class? panoss 2 3,636 Jan-10-2017, 08:10 AM
Last Post: panoss
  [Tkinter] createing a tkinter photoimage from array in python3 pootle 2 16,900 Oct-18-2016, 09:28 AM
Last Post: pootle

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020