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):
"""initiali zer for Tkinter-based application"""
self.root=root
F1 = Tk.Frame(self.r oot)
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.r oot)
F2.pack()
self.ImageLabel = Tk.Label(F2)
self.ImageLabel .pack()
self.FilenameLa bel = Tk.Label(F2)
self.FilenameLa bel.pack()
def go(self):
filenames = ["DSCN0184.J PG", "DSCN0185.J PG", "DSCN0186.J PG"]
for name in filenames:
im=Image.open(n ame)
im.thumbnail((1 00,75))
Tkimage = ImageTk.PhotoIm age(im)
self.ImageLabel .config(image=T kimage)
self.FilenameLa bel.config(text =name)
time.sleep(2)
raw_input("Pres s ENTER for next...")
root = Tk.Tk()
myapp = MyApp(root)
root.mainloop()
=============== ===========
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):
"""initiali zer for Tkinter-based application"""
self.root=root
F1 = Tk.Frame(self.r oot)
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.r oot)
F2.pack()
self.ImageLabel = Tk.Label(F2)
self.ImageLabel .pack()
self.FilenameLa bel = Tk.Label(F2)
self.FilenameLa bel.pack()
def go(self):
filenames = ["DSCN0184.J PG", "DSCN0185.J PG", "DSCN0186.J PG"]
for name in filenames:
im=Image.open(n ame)
im.thumbnail((1 00,75))
Tkimage = ImageTk.PhotoIm age(im)
self.ImageLabel .config(image=T kimage)
self.FilenameLa bel.config(text =name)
time.sleep(2)
raw_input("Pres s ENTER for next...")
root = Tk.Tk()
myapp = MyApp(root)
root.mainloop()
=============== ===========
Comment