Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8028145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:02:38+00:00 2026-06-05T00:02:38+00:00

I’m trying to implement the undo function for my image editing program. Below is

  • 0

I’m trying to implement the undo function for my image editing program. Below is part of my code:

def displayim(root, panel, img, editmenu):
    global image, L
    L.append(img)
    print(len(L))
    if (len(L) > 1):
        editmenu.entryconfig(0, state=NORMAL)
    else:
        editmenu.entryconfig(0, state=DISABLED)    
    image1 = ImageTk.PhotoImage(img)
    root.geometry("%dx%d+%d+%d" % (img.size[0], img.size[1], 200, 200))
    panel.configure(image = image1)
    panel.pack(side='top', fill='both', expand='yes')
    panel.image = image1
    image = img

def undo(root, panel, editmenu):
    global L
    i = len(L)
    del L[i-1]
    last = L.pop
    displayim(root, panel, last, editmenu)

My idea is that when any function for opening image or adding effect to image is called, it will display the result by calling displayim. The parameter editmenu makes sure that if there is nothing to undo, the undo command will be disabled. Variable L is a list used to store the states of image after each function is called. When the undo function is invoked, it would remove the last item in the list and also the one before the last item (now became the last), and pass this new last item to displayim so that the program can display the previous state of the image and add it to the list again.

However, when I try to use the undo function, I got the error:

Exception in Tkinter callback
Traceback (most recent call last):
  File "D:\Python32\lib\tkinter\__init__.py", line 1399, in __call__
    return self.func(*args)
  File "D:\Users\ichigo\workspace\SS2\test\main.py", line 26, in <lambda>
    editmenu.add_command(label="Undo", command=lambda:file.undo(root, panel, editmenu), state=DISABLED)
  File "D:\Users\ichigo\workspace\SS2\test\file.py", line 51, in undo
    displayim(root, panel, last, editmenu)
  File "D:\Users\ichigo\workspace\SS2\test\file.py", line 39, in displayim
    image1 = ImageTk.PhotoImage(img)
  File "D:\Python32\lib\site-packages\PIL\ImageTk.py", line 110, in __init__
    mode = Image.getmodebase(mode)
  File "D:\Python32\lib\site-packages\PIL\Image.py", line 225, in getmodebase
    return ImageMode.getmode(mode).basemode
  File "D:\Python32\lib\site-packages\PIL\ImageMode.py", line 50, in getmode
    return _modes[mode]
TypeError: unhashable type: 'list'
Exception AttributeError: "'PhotoImage' object has no attribute '_PhotoImage__photo'" in <bound method PhotoImage.__del__ of <PIL.ImageTk.PhotoImage object at 0x01B1AA50>> ignored 

I guess the error means the variable last I passed to displayim from undo isn’t a PIL image object so it can’t be added to PhotoImage. Is there any solution available for me now? Please tell me if you have any suggestions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T00:02:39+00:00Added an answer on June 5, 2026 at 12:02 am

    You should change last = L.pop to last = L.pop()

    L.pop return a <build-in method pop of list object> but not a PIL image object

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.