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

  • SEARCH
  • Home
  • 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 7707931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:28:58+00:00 2026-06-01T00:28:58+00:00

I’m currently trying to setup a GUI in Tkinter so that I can show

  • 0

I’m currently trying to setup a GUI in Tkinter so that I can show a sequence of images (named file01.jpg, file02.jpg, etc. etc.). Currently I’m doing it by creating a Sequence object to manage the list of images that I care about:

class Sequence:
    def __init__(self,filename,extension):
        self.fileList = []
        #takes the current directory
        listing = os.listdir(os.getcwd())
        #and makes a list of all items in that directory that contains the filename and extension
        for item in listing:
            if filename and extension in item:
                self.fileList.append(item)
        #and then sorts them into order
        self.fileList.sort()
        print self.fileList

    def nextImage(self):
        #returns a string with the name of the next image
        return self.fileList.pop(0)

And then I’m using a rather simple Tkinter script I found online to generate the window and place an image there:

window = Tkinter.Tk()
window.title('Image Analysis!')
sequence = Sequence('test','jpg')

image = Image.open("test01.jpg")
image = image.convert('L')
imPix = image.load()
canvas = Tkinter.Canvas(window, width=image.size[0], height=image.size[1])
canvas.pack()
image_tk = ImageTk.PhotoImage(image)
canvas.create_image(image.size[0]//2, image.size[1]//2, image=image_tk)
window.bind("<space>", lambda e: nextFrame(sequence_object=sequence,event=e))
Tkinter.mainloop()

where nextFrame is defined as:

def nextFrame(sequence_object,event=None):
    nextImage = sequence_object.nextImage()
    print 'Next Image is: ',nextImage
    image = Image.open(nextImage)
    image = image.convert('L')
    imPix = image.load()
    image_tk = ImageTk.PhotoImage(image)
    canvas.create_image(image.size[0]//2, image.size[1]//2, image=image_tk)
    canvas.update()

In my python buffer I see the correct image sequence pop up (‘Next Image is: test02,jpg’, etc.) but the new image never pops up!

Does anyone have any explanation for why the image doesn’t pop up?

Thanks!

nathan lachenmyer

  • 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-01T00:29:00+00:00Added an answer on June 1, 2026 at 12:29 am

    Probably what is happening is that the image is getting destroyed by the garbage collector since the only reference to the image is a local variable.

    Try keeping a permanent reference to the image, for example:

    ...
    self.image_tk = ImageTk.PhotoImage(image)
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am currently running into a problem where an element is coming back from

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.