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.pac k()
self.cronoUpIma geList =[
"cronoup1.g if", "cronoup2.g if", "cronoup3.g if",
"cronoup4.g if", "cronoup5.g if", "cronoup6.g if"]
self.gifImage = PhotoImage(file =self.cronoUpIm ageList[0])
self.cronoDefUp = PhotoImage(file ="cronodefup.gi f")
self.drawImage = self.canvas.cre ate_image(112.5 , 100, image=
self.cronoDefUp )
self.canvas.bin d("<Up>", self.keyboardPr sUp)
self.canvas.bin d("<Down>", self.keyboardRl sUp)
def keyboardPrsUp(s elf, event):
self.canvas.del ete(self.drawIm age)
self.counter = 0
self.killEvent = False
while self.killEvent != True:
print self.cronoUpIma geList[self.counter]
self.gifImage =
PhotoImage(file =self.cronoUpIm ageList[self.counter])
self.drawImage = self.canvas.cre ate_image(112.5 , 100,
image=
self.gifImage)
self.counter = self.counter + 1
if self.counter 5:
self.counter = 0
self.canvas.upd ate()
sleep(.05)
def keyboardRlsUp(s elf, event):
self.counter = 0
self.killEvent = True
self.canvas.del ete(self.drawIm age)
self.drawImage = self.canvas.cre ate_image(112.5 , 100, image=
self.cronoDefUp )
root = Tk()
root.title("GIF Animation Test")
app = GIF(root)
root.mainloop() 1 2901 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.pac k()
self.cronoUpIma geList =[
"cronoup1.g if", "cronoup2.g if", "cronoup3.g if",
"cronoup4.g if", "cronoup5.g if", "cronoup6.g if"]
self.gifImage = PhotoImage(file =self.cronoUpIm ageList[0])
self.cronoDefUp = PhotoImage(file ="cronodefup.gi f")
self.drawImage = self.canvas.cre ate_image(112.5 , 100, image=
self.cronoDefUp )
self.canvas.bin d("<Up>", self.keyboardPr sUp)
self.canvas.bin d("<Down>", self.keyboardRl sUp)
def keyboardPrsUp(s elf, event):
currentTime = ...
if( currentTime - self.timeOfLast KeyPush < self.minDelay):
pass
else:
self.timeOfLast KeyPush = currentTime
...
self.canvas.del ete(self.drawIm age)
self.counter = 0
self.killEvent = False
while self.killEvent != True:
print self.cronoUpIma geList[self.counter]
self.gifImage =
PhotoImage(file =self.cronoUpIm ageList[self.counter])
self.drawImage = self.canvas.cre ate_image(112.5 , 100,
image=
self.gifImage)
self.counter = self.counter + 1
if self.counter 5:
self.counter = 0
self.canvas.upd ate()
sleep(.05)
def keyboardRlsUp(s elf, event):
self.counter = 0
self.killEvent = True
self.canvas.del ete(self.drawIm age)
self.drawImage = self.canvas.cre ate_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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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, "+")
|
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 somebody clue me in regarding how this is
done? Muchas gracias.
Peace
|
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 command-q so that it
quits the application (this is standard behavior for almost every mac
application, the equivalent of alt-f4 on windows). Has anyone
successfully been able to do this? If so, could you please share some
code which...
|
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 I am hoping someone knows what I am
doing wrong:
1) Pressing the Settings.. Button multiple times, brings up many instances
of the Settings Panel. I just want it to bring up one. Is there an easy
way to do that?
|
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:
Current entry
Company : entered co. name
First entry : entered stuff
The second entry: more entered stuff
| |
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 most frustrating, as there is no
friendly traceback to help me guess where its coming from.
|
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
SIGQUIT signals using keyboard input.
Anyone could give me a little hint ?
thanks
|
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 location as the key, and alternate, or connecting locations as the definition to the key. Now I need to 'interrupt' the path and give it a new path based on a keyboard event, like an arrow up, left, down or right. At the next key point if there is a...
|
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
this I mean that the format would be something like this:
You have Page1 : This has 2-3 buttons on it.
Clicking on each button opens up a new window respectively having
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |