I've been having a lot of trouble with the after
method. What I want to do is show a series of images at the push of a button/press of a key -- each image should appear for 500ms, then be replaced by the next image, which should go on indefinitely (or end at the push/release of another button/key). It seems like I should be able to use after
to accomplish this, but all my attempts so far have just resulted in recursion errors.
Here is the relevant code so far:
from Tkinter import *
import os
root = Tk()
root.option_readfile('OptionsDB.txt')
frame = Frame(root)
frame.pack()
# finds the screen size
sw = root.winfo_screenwidth()
sh = root.winfo_screenheight()
# expands window to full screen
root.geometry("%dx%d+0+0" % (sw, sh))
# images
smiley = PhotoImage(file = 'Smiley-small.gif')
frowny = PhotoImage(file = 'Frowny-small.gif')
class judgmentPage:
def __init__(self):
# a frame inside the main frame that can be destroyed later
self.innerframe = Frame(frame)
self.innerframe.pack(expand=YES, fill=BOTH)
# the canvas for displaying images
self.canvas = Canvas(bg = 'white')
self.canvas.pack(side=LEFT, expand = YES, fill = BOTH)
self.button = Button(self.innerframe, text="Start Judgments", command=self.showJudgments)
self.button.pack(side=LEFT)
def showJudgments(self):
self.image = self.canvas.create_image(500, 500, image = smiley, anchor=S)
self.innerframe.after(500, self.update())
def update(self):
self.canvas.delete(self.image)
self.innerframe.after(500, self.showJudgments())
page = judgmentPage()
root.mainloop()
I've considered that it may have to do with the canvas -- maybe I am not using it correctly. Should I be using labels instead?
Cheers,
noob Aot