Inserting Unicode chars in Entry widget

Chris Angelico rosuav at
Sat Dec 29 18:23:07 CET 2012

On Sun, Dec 30, 2012 at 4:11 AM, Irmen de Jong <irmen.NOSPAM at> wrote:
> b1=Button(f, text='char1', command=lambda b=1: insert_char(b))
> b2=Button(f, text='char2', command=lambda b=2: insert_char(b))
> ...etc..
> def insert_char(b):
>     if b==1:
>         entrywidget.insert(0, u"\u20ac")   # inserts € in the entry widget e
>     elif b==2:
>         entrywidget.insert(0, ...some other char...)
>     ...

I'm not familiar with tkinter syntax, but why not:

b1=Button(f, text='char1', command=lambda: insert_char(1))
b2=Button(f, text='char2', command=lambda: insert_char(2))

or even:

b1=Button(f, text='char1', command=lambda: insert_char(u"\u20ac"))
b2=Button(f, text='char2', command=lambda: insert_char("... some other

Seems weird to multiplex like that, but if there's a good reason for
it, sure. I'm more of a GTK person than tkinter, and more of a
command-line guy than either of the above.


More information about the Python-list mailing list