[Tutor] problems with dictionary

Alan Gauld alan.gauld at freenet.co.uk
Wed Mar 23 23:37:53 CET 2005


> D={a:"tom", b:"dick", c:"harry"}

You don't have quotes around the keys.

>
> text.bind('<Key>', self.Conv)
>
> def Conv(self,event):

The fact that you have 'self' as a first parameter to COnv and 
as a second argument to bind suggests this is all part of a 
class definition? Is D part off the same class? 
If so you need:

>    if D.has_key(event.keysym):

     if self.D.has_key(event.keysym)

    self.text.insert(END,str)

And you use self.text here but not where you call bind?

It seems that this is only pseudo code.
It might be easier if you send us the real code - or a 
fragment that shows the same problem. 

Also you don't say what does happen? Is there an error message 
in the console? Does anything get printed? Error reports are 
extremely helpful in diagnosing problems.

Alan G.


More information about the Tutor mailing list