By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,218 Members | 1,236 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,218 IT Pros & Developers. It's quick & easy.

Tkinter: How can I update an image display?

P: n/a
I've got a small batch image-processing program (it adds the time a
digital photo was taken to the lower right of the image), and as a
feature, I wanted to show a thumbnail of each image it was being
processed. I can't get the image to update, though.

I trimmed it down to a basic app indicating the problem and the code
is at the end of this message. It should display the three listed
sample images, one after another.

The thing is, if I uncomment the raw_input call, it works. But I
don't want to have to hit ENTER after each image.

At first I wondered whether maybe the image data was bad, but that
doesn't explain why it works fine with the raw_input call in place.

I've hardly played with Tkinter, so I'm probably missing something
obvious. I tried adding pack() calls for F2 and ImageLabel, and that
made no difference.

Ideas?

Here's the code:

==========================
import Tkinter as Tk
import os, sys, time
import Image, ImageTk

class MyApp:

def __init__(self, root):
"""initializer for Tkinter-based application"""
self.root=root
F1 = Tk.Frame(self.root)
F1.pack()
SelButton = Tk.Button(F1, text="Go", command=self.go)
SelButton.pack(side="left")
QuitButton = Tk.Button(F1, text="Quit", command=F1.quit)
QuitButton.pack(side="left")
F2 = Tk.Frame(self.root)
F2.pack()
self.ImageLabel = Tk.Label(F2)
self.ImageLabel.pack()
self.FilenameLabel = Tk.Label(F2)
self.FilenameLabel.pack()
def go(self):
filenames = ["DSCN0184.JPG", "DSCN0185.JPG", "DSCN0186.JPG"]
for name in filenames:
im=Image.open(name)
im.thumbnail((100,75))
Tkimage = ImageTk.PhotoImage(im)
self.ImageLabel.config(image=Tkimage)
self.FilenameLabel.config(text=name)
time.sleep(2)
raw_input("Press ENTER for next...")

root = Tk.Tk()
myapp = MyApp(root)
root.mainloop()
==========================

Jul 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Sun, 05 Jun 2005 20:39:04 -0700, Terry Carroll
<ca*****@nospam-tjc.com> wrote:
The thing is, if I uncomment the raw_input call, it works. But I
don't want to have to hit ENTER after each image.


And the, just to be confusing, I posted the uncommented version.

To make my example more consistent with my post, I should have said
that, when the raw_input call is commented out, it no longer works.
Jul 19 '05 #2

P: n/a
Terry Carroll <ca*****@nospam-tjc.com> writes:
I trimmed it down to a basic app indicating the problem and the code
is at the end of this message. It should display the three listed
sample images, one after another.

The thing is, if I uncomment the raw_input call, it works. But I
don't want to have to hit ENTER after each image.


Try using root.update()?
Jul 19 '05 #3

P: n/a
On 05 Jun 2005 21:04:40 -0700, Paul Rubin
<http://ph****@NOSPAM.invalid> wrote:
Try using root.update()?


Thanks!
Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.