Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #91067

Re: need help with an accessibility prototype

From Laura Creighton <lac@openend.se>
Subject Re: need help with an accessibility prototype
References <555F5960.9030501@harvee.org>
Date 2015-05-22 21:50 +0200
Newsgroups comp.lang.python
Message-ID <mailman.237.1432324217.17265.python-list@python.org> (permalink)

Show all headers | View raw


In a message of Fri, 22 May 2015 12:29:20 -0400, "Eric S. Johansson" writes:
>2 needs.  first is determining if NaturallySpeaking injects keycodes or 
>ascii char into the windows input queue.  second is building a test 
>widget to capture and display text.
>
>I think I can solve both of these by building a simple text widget 
>(tkinter? qt? ??) to capture keycodes.  problem, is in <mumble><mumble> 
>yrs of programming, I've never written a GUI interface so I have no idea 
>where to start.  help, tutor, pointers to samples would be most welcome.
>
>--- eric

The best online manual I know of for Tkinter is here:
http://effbot.org/tkinterbook/ despite being 10 years old.  But then I
haven't looked for one for about that long, either.

For tkinter key events are a  bit odd, given that Tkinter tries to
help you and considers special keys, punctuation and non-ascii printing
characters as separate things should you want to bind to them.

It's actually easier to write the code and say 'play with this' rather
than to explain when you would need to use event.char and when event.keysym
(Plus the code will tell you what Tkinter uses, I might remember wrong.)

Save this in a file and run it.

from Tkinter import *
root = Tk()
prompt = 'Press any key.  Remember to keep your mouse in the cyan box. '
lab = Label(root, text=prompt, width=len(prompt), bg='cyan')
lab.pack()

def key(event):
    msg = 'event.char is %r and event.keysym is %r' % (event.char, event.keysym)
        lab.config(text=msg)

root.bind_all('<Key>', key)
root.mainloop()

----------
If you need to put unicode chars in your label, that's a different probem.
If knowing when a control or alt-gr key is released is important to you,
the code will have to be modified to detect this specially.  Type some
control chars at the cyan window and you will see what I mean.

Happy Hacking,
Laura

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: need help with an accessibility prototype Laura Creighton <lac@openend.se> - 2015-05-22 21:50 +0200

csiph-web