[Tutor] call key on_press event multiple times when key is held down

Carlton Banks noflaco at gmail.com
Thu Jul 13 03:36:15 EDT 2017


So i finally made it work.. 
My error was caused in the callback function, which
aborted the stream, hence didn’t record. 

This was the solution I ended with:

https://pastebin.com/isW2brW2 <https://pastebin.com/isW2brW2>


> Den 10. jul. 2017 kl. 11.10 skrev Alan Gauld via Tutor <tutor at python.org>:
> 
> On 04/07/17 13:45, Carlton Banks wrote:
> 
>> Any suggestion on any GUI solutions?
> 
> Here is a Tkinter solution that increments a counter
> while the mouse button is pressed. It should give you the idea...
> Obviously you need to replace the counter increment
> with your desired processing. And the print statements
> are just to show the events being processed.
> 
> ##################################
> import tkinter as tk
> 
> display = "count: "
> flag = False
> counter = 0
> 
> def do_down(e):
>    global flag
>    print('Key down')
>    flag = True
>    after_loop()
> 
> def do_up(e):
>    global flag
>    print('key up')
>    flag = False
> 
> def after_loop():
>    print('looping')
>    global counter
>    counter += 1
>    l['text'] = display +str(counter)
>    if flag:
>       top.after(10,after_loop)
> 
> 
> top = tk.Tk()
> l = tk.Label(top,text=display+'0')
> l.pack()
> l.bind("<Button-1>",do_down)
> l.bind("<ButtonRelease-1>",do_up)
> top.mainloop()
> 
> ###################################
> 
> HTH
> -- 
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list