Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ImageTk Paste
#5
I think due to Namespace flooding with * imports you've learnt your lesson in why to not do it.

The code is expecting a PIL Image instead I think its got a tkinter Image which has no load method see the tk Image class below.
class Image:
    """Base class for images."""
    _last_id = 0

    def __init__(self, imgtype, name=None, cnf={}, master=None, **kw):
        self.name = None
        if not master:
            master = _get_default_root('create image')
        self.tk = getattr(master, 'tk', master)
        if not name:
            Image._last_id += 1
            name = "pyimage%r" % (Image._last_id,) # tk itself would use image<x>
        if kw and cnf: cnf = _cnfmerge((cnf, kw))
        elif kw: cnf = kw
        options = ()
        for k, v in cnf.items():
            if callable(v):
                v = self._register(v)
            options = options + ('-'+k, v)
        self.tk.call(('image', 'create', imgtype, name,) + options)
        self.name = name

    def __str__(self): return self.name

    def __del__(self):
        if self.name:
            try:
                self.tk.call('image', 'delete', self.name)
            except TclError:
                # May happen if the root was destroyed
                pass

    def __setitem__(self, key, value):
        self.tk.call(self.name, 'configure', '-'+key, value)

    def __getitem__(self, key):
        return self.tk.call(self.name, 'configure', '-'+key)

    def configure(self, **kw):
        """Configure the image."""
        res = ()
        for k, v in _cnfmerge(kw).items():
            if v is not None:
                if k[-1] == '_': k = k[:-1]
                if callable(v):
                    v = self._register(v)
                res = res + ('-'+k, v)
        self.tk.call((self.name, 'config') + res)

    config = configure

    def height(self):
        """Return the height of the image."""
        return self.tk.getint(
            self.tk.call('image', 'height', self.name))

    def type(self):
        """Return the type of the image, e.g. "photo" or "bitmap"."""
        return self.tk.call('image', 'type', self.name)

    def width(self):
        """Return the width of the image."""
        return self.tk.getint(
            self.tk.call('image', 'width', self.name))
Try removing from tkinter import * and using import tkinter as tk from now on.
Reply


Messages In This Thread
ImageTk Paste - by KDog - May-31-2021, 09:47 PM
RE: ImageTk Paste - by bowlofred - May-31-2021, 10:29 PM
RE: ImageTk Paste - by Yoriz - May-31-2021, 10:31 PM
RE: ImageTk Paste - by KDog - Jun-01-2021, 03:07 PM
RE: ImageTk Paste - by Yoriz - Jun-01-2021, 04:40 PM
RE: ImageTk Paste - by KDog - Jun-01-2021, 09:19 PM
RE: ImageTk Paste - by Yoriz - Jun-01-2021, 10:16 PM
RE: ImageTk Paste - by deanhystad - Jun-01-2021, 10:20 PM
RE: ImageTk Paste - by KDog - Jun-02-2021, 11:28 AM
RE: ImageTk Paste - by Yoriz - Jun-02-2021, 11:39 AM
RE: ImageTk Paste - by KDog - Jun-02-2021, 12:54 PM
RE: ImageTk Paste - by deanhystad - Jun-02-2021, 05:06 PM
RE: ImageTk Paste - by KDog - Jun-02-2021, 09:42 PM
RE: ImageTk Paste - by deanhystad - Jun-03-2021, 03:27 AM
RE: ImageTk Paste - by KDog - Jun-27-2021, 11:07 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  What script to paste folders thenewcoder 1 677 Nov-29-2023, 09:40 AM
Last Post: Pedroski55
  PIL ImageTk issue with MATPLOTLIB garynewport 0 1,799 Jan-17-2023, 11:32 AM
Last Post: garynewport
  Please help me [copy and paste file from src to dst] midomarc 2 1,027 Nov-24-2022, 10:13 PM
Last Post: midomarc
  Cut and Paste Oshadha 3 2,449 Jan-20-2021, 04:27 PM
Last Post: spaceraiders
  copy paste file and re-name it asheru93 1 2,384 May-24-2019, 10:43 AM
Last Post: heiner55

Forum Jump:

User Panel Messages

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