ich bin Python-Neuling und möchte gern Images hintereinander anzeigen lassen
(Film abspielen). Ich habe ein Beispiel gefunden, wo man durch Mausklicks jeweils
das nächste Image anzeigen lassen kann (s.u.). Möchte nun aber anstatt der
Mausklick-Events Zeitevents als Auslöser nehmen, habe aber nichts gefunden,
was mir dabei hilft.
(Wie) Kann ich mir selbst events herstellen (hier wird ja das vorgegebene <Button>
event verwendet)?
Oder hat jemand vielleicht eine andere Idee? In Matlab gibt es movies, da ist es
extrem simpel, man schreibt einfach nur seine Bilder in eine große Variable und läßt
dann alles laufen. Gibt es so etwas einfaches auch in Python? Ich habe gesucht
und nichts gefunden.
ich bin für jeden Hinweis dankbar,
Anton
Code: Alles auswählen
import os, sys
import Tkinter
import Image, ImageTk
def myevent (event):
event.widget.quit() # this will cause mainloop to unblock.
root = Tkinter.Tk()
root.bind("<Button>", myevent)
root.geometry('+%d+%d' % (100,100))
dirlist = os.listdir('.')
old_label_image = None
for f in dirlist:
try:
image1 = Image.open(f)
root.geometry('%dx%d' % (image1.size[0],image1.size[1]))
tkpi = ImageTk.PhotoImage(image1)
label_image = Tkinter.Label(root, image=tkpi)
label_image.place(x=0,y=0,width=image1.size[0],height=image1.size[1])
root.title(f)
if old_label_image is not None:
old_label_image.destroy()
old_label_image = label_image
root.mainloop() # wait until user clicks the window
except Exception, e:
# This is used to skip anything not an image.
# Image.open will generate an exception if it cannot open a file.
# Warning, this will hide other errors as well.
pass