[EMAIL PROTECTED] wrote:
Hello,
I have created a simple canvas in Tkinter to display a number of
PhotoImages, I then bind a key (in my case, Up) to start a loop that
plays through a list of PhotoImages to make it an animation of sorts.
What I noticed is, after holding down the key for a certain time, it
would not loop through all 6 animations, instead it would just go
through the first 2 and reset it self. I changed the key bind to
Button-1 and did not encounter this problem. I then went into my
keyboard hardware settings and changed the repeat rate to the longest
delay and the repeat delay to the longest delay. This improved it some
what, but I don't think it is practical to do this everytime I start up
the program. My question is, is there a way to bind a key so as to make
it ignore the keyboard's delay and repeat rate settings? Here's the
code just so you can get an idea:
# GIF Animation Test
from Tkinter import *
from time import sleep
class GIF:
def __init__(self, root):
self.root = root
self.canvas = Canvas(root, bg=white, width=225, height=200)
self.canvas.pack()
self.cronoUpImageList =[
cronoup1.gif, cronoup2.gif, cronoup3.gif,
cronoup4.gif, cronoup5.gif, cronoup6.gif]
self.gifImage = PhotoImage(file=self.cronoUpImageList[0])
self.cronoDefUp = PhotoImage(file=cronodefup.gif)
self.drawImage = self.canvas.create_image(112.5, 100, image=
self.cronoDefUp)
self.canvas.bind(Up, self.keyboardPrsUp)
self.canvas.bind(Down, self.keyboardRlsUp)
def keyboardPrsUp(self, event):
currentTime = ...
if( currentTime - self.timeOfLastKeyPush self.minDelay):
pass
else:
self.timeOfLastKeyPush = currentTime
...
self.canvas.delete(self.drawImage)
self.counter = 0
self.killEvent = False
while self.killEvent != True:
print self.cronoUpImageList[self.counter]
self.gifImage =
PhotoImage(file=self.cronoUpImageList[self.counter])
self.drawImage = self.canvas.create_image(112.5, 100,
image=
self.gifImage)
self.counter = self.counter + 1
if self.counter 5:
self.counter = 0
self.canvas.update()
sleep(.05)
def keyboardRlsUp(self, event):
self.counter = 0
self.killEvent = True
self.canvas.delete(self.drawImage)
self.drawImage = self.canvas.create_image(112.5, 100, image=
self.cronoDefUp)
root = Tk()
root.title(GIF Animation Test)
app = GIF(root)
root.mainloop()
What about simple tracking of time (see above NOT tested rough draft) in
the keyboardPrsUp and keyboardRlsUp functions, so, that events raised
earlier than after a specified delay period will just become ignored?
Claudio Grondi
--
http://mail.python.org/mailman/listinfo/python-list