[Tutor] problems with dictionary

Igor Riabtchuk igor.r at vodafone.net
Wed Mar 23 21:49:11 CET 2005

was wondering whether you can help?

Say I got a dictionary of keys:values :

And what I want to do is depending on what key (a,b,c) the person presses, I want to output the value (tom, dic, harry).

So I program like this:

import Tkinter

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

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

def Conv(self,event):
    if D.has_key(event.keysym):
        str="The name is"+str
    return 'break'

(If I had to do each one (i.e. without the dictionary) I would do as follows:

def Conv(self,event):
    if event.keysym==a:
    self.text(END, str)
    return 'break'

There is clearly a mistake in the first function, only thing is I cannot spot it and thus the thing does not work.

Any ideas?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050323/0ca3347f/attachment.html

More information about the Tutor mailing list