Inserting Unicode chars in Entry widget
Irmen de Jong
irmen.NOSPAM at xs4all.nl
Sat Dec 29 18:11:22 CET 2012
On 29-12-2012 17:43, Alan Graham wrote:
> Hello Python experts,
> I want to insert Unicode chars in an Entry widget by pushing on buttons;
> one for each Unicode character I need. I have made the Unicode buttons.
> I just need a simple function that will send the Unicode character to
> the Entry widget.
> Is there a better approach?
Not sure what the question is. A better approach to doing what?
I assuming you're doing tkinter (it is helpful if you mention the toolkit when posting a
question). I'd create a function that you bind to all 'unicode buttons', and let the
function insert the correct character depending on which button triggered it.
A possible way to do that is to use a lambda with a different parameter for every
button, like this:
b1=Button(f, text='char1', command=lambda b=1: insert_char(b))
b2=Button(f, text='char2', command=lambda b=2: insert_char(b))
entrywidget.insert(0, u"\u20ac") # inserts € in the entry widget e
entrywidget.insert(0, ...some other char...)
Or simply define a different command function for every button, then you don't have to
use the lambda.
More information about the Python-list