Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Tkinter binding and keyboard hardware settings (WinXP)

Reply
Thread Tools

Tkinter binding and keyboard hardware settings (WinXP)

 
 
apriebe47@gmail.com
Guest
Posts: n/a
 
      07-10-2006
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):
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()

 
Reply With Quote
 
 
 
 
Claudio Grondi
Guest
Posts: n/a
 
      07-10-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Settings.settings file with settings for multiple regions donet programmer ASP .Net 3 11-20-2009 03:05 PM
COMPUTER HARDWARE like hard disk, keyboard, mouse, pen-drive shopping.portal18@gmail.com Python 0 07-28-2009 01:10 PM
dll config and web.config and Label Expressions (binding label text to dll config settings) CSharpner ASP .Net 0 04-09-2007 09:00 PM
Help with Tkinter and stdin input event binding Diogo Bastos Python 0 09-25-2006 02:10 PM
value binding and function binding Vivek Nallur Ruby 0 09-25-2003 02:52 AM



Advertisments