[Tutor] Changing Keyboard output

2005-03-20 Thread Igor Riabtchuk



Hi,

I am totally new to Python and still 
learning.

I am looking for a way to change keyboard output 
within Tkinter widget - for example, say I press "p" and I want it to come out 
as "t".

Could anyone possibly point me in the right 
direction?

Igor 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Changing Keyboard output

2005-03-20 Thread Michael Lange
On Sun, 20 Mar 2005 19:38:40 -
Igor Riabtchuk [EMAIL PROTECTED] wrote:

 Hi,
 
 I am totally new to Python and still learning.
 
 I am looking for a way to change keyboard output within Tkinter widget - for 
 example, say I press p and I want it to come out as t.
 
 Could anyone possibly point me in the right direction?
 
 Igor 

You can use the widget's bind() method to replace the standard callback with a 
new one:

from Tkinter import *
root = Tk()
e = Entry(r)
e.pack()

def PtoT(event):
e.insert('insert', 't')
return 'break'

e.bind('p', PtoT)

the return 'break' statement prevents the event from being propagated to Tk's 
standard event handler;
without it both p and t would be inserted into the Entry.

I hope this helps

Michael
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Changing Keyboard output

2005-03-20 Thread Alan Gauld
 I am looking for a way to change keyboard output within 
 Tkinter widget - for example, say I press p and I want 
 it to come out as t.

 Could anyone possibly point me in the right direction?

Take a look at the Event Driven programming topic in my tutor, 
it covers reading keyboard input in Tkinter.

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor