473,396 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Tkinter binding and keyboard hardware settings (WinXP)

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()

Jul 10 '06 #1
1 2880
ap*******@gmail.com 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
Jul 10 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Rodrigo Benenson | last post by:
Hi, I have a weird need in tkinter. If I have a widget I can *set* a binding ..bind("<the event>", the_callback) I also can *append* a binding ..bind("<the event>", the_second_callback,...
6
by: Elaine Jackson | last post by:
I've got a script where a button gets pushed over and over: to cut down on the carpal tunnel syndrome I'd like to have the button respond to presses of the Enter key as well as mouse clicks; can...
0
by: Brandon | last post by:
Hi All, I'm attempting to develop a Tcl/Tk application on the mac using python and Tkinter. The one problem I'm having is adding basic keyboard support to my application, specifically binding...
1
by: Michael Yanowitz | last post by:
Hello: Below I have included a stripped down version of the GUI I am working on. It contains 2 dialog boxes - one main and one settings. It has the following problems, probably all related, that...
5
by: H J van Rooyen | last post by:
Hi, I am struggling to get the pack method to do what I intend. I am trying to display user input in a seperate window, along with a little description of the field, something like this: ...
14
by: Hendrik van Rooyen | last post by:
Hi, I get the following: hvr@LINUXBOXMicrocorp:~/Controller/libpython display.py UpdateStringProc should not be invoked for type font Aborted and I am back at the bash prompt - this is...
8
by: RJ45 | last post by:
Hello, I am writing a shell in C. I need to intercept Signals like CTRL+C or CTRL+D and set to ignore them. This is on Unix, using gcc. my goal is to avoid users escaping the shell with SIGINT...
3
TMS
by: TMS | last post by:
Hey all: I'm working on this 'pac man' like game I've been writing in Tkinter. The temporary gif I'm using (I can't attach it, sorry) goes around the maze based on a dictionary that has each path...
3
by: J-Burns | last post by:
Hello. Im a bit new to using Tkinter and im not a real pro in programming itself... :P. Need some help here. Problem 1: How do I make something appear on 2 separate windows using Tkinter? By...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.