Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #35753 > unrolled thread

Inserting Unicode chars in Entry widget

Started byAlan Graham <alan.l.graham@gmail.com>
First post2012-12-29 08:43 -0800
Last post2012-12-29 20:15 +0100
Articles 5 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  Inserting Unicode chars in Entry widget Alan Graham <alan.l.graham@gmail.com> - 2012-12-29 08:43 -0800
    Re: Inserting Unicode chars in Entry widget Chris Angelico <rosuav@gmail.com> - 2012-12-30 03:58 +1100
    Re: Inserting Unicode chars in Entry widget Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2012-12-29 18:11 +0100
      Re: Inserting Unicode chars in Entry widget Chris Angelico <rosuav@gmail.com> - 2012-12-30 04:23 +1100
        Re: Inserting Unicode chars in Entry widget Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2012-12-29 20:15 +0100

#35753 — Inserting Unicode chars in Entry widget

FromAlan Graham <alan.l.graham@gmail.com>
Date2012-12-29 08:43 -0800
SubjectInserting Unicode chars in Entry widget
Message-ID<df4d0902-c40a-42de-8a6c-b997460313a9@googlegroups.com>
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?

Alan

[toc] | [next] | [standalone]


#35755

FromChris Angelico <rosuav@gmail.com>
Date2012-12-30 03:58 +1100
Message-ID<mailman.1429.1356800290.29569.python-list@python.org>
In reply to#35753
On Sun, Dec 30, 2012 at 3:43 AM, Alan Graham <alan.l.graham@gmail.com> 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?

What GUI toolkit are you using?

Whatever it is, there ought to be a simple method on the Entry widget
that inserts a character. Poke around with it and you'll probably find
it, though you may find it under a name you don't expect. (Happens a
lot. GTK calls something "sensitive" when the rest of the world calls
it "enabled".)

ChrisA

[toc] | [prev] | [next] | [standalone]


#35758

FromIrmen de Jong <irmen.NOSPAM@xs4all.nl>
Date2012-12-29 18:11 +0100
Message-ID<50df2439$0$6948$e4fe514c@news.xs4all.nl>
In reply to#35753
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?
> 
> Alan
> 

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))
...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...)
    ...


Or simply define a different command function for every button, then you don't have to
use the lambda.

-irmen

[toc] | [prev] | [next] | [standalone]


#35759

FromChris Angelico <rosuav@gmail.com>
Date2012-12-30 04:23 +1100
Message-ID<mailman.1432.1356801796.29569.python-list@python.org>
In reply to#35758
On Sun, Dec 30, 2012 at 4:11 AM, Irmen de Jong <irmen.NOSPAM@xs4all.nl> 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
char..."))

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.

ChrisA

[toc] | [prev] | [next] | [standalone]


#35766

FromIrmen de Jong <irmen.NOSPAM@xs4all.nl>
Date2012-12-29 20:15 +0100
Message-ID<50df413f$0$6921$e4fe514c@news.xs4all.nl>
In reply to#35759
On 29-12-2012 18:23, Chris Angelico wrote:
> On Sun, Dec 30, 2012 at 4:11 AM, Irmen de Jong <irmen.NOSPAM@xs4all.nl> 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
> char..."))
> 
> 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.
> 
> ChrisA
> 

You're right there's nothing special about tkinter there, I was copying some existing
code a bit too literally. Simplify the lambdas as needed. :)

Irmen

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web