Converting Unicode to integer

Nikola Plejic Nikola.Plejic at pu.CARNet.hr
Tue Aug 27 09:43:11 EDT 2002


Oh, okay, sorry (feeling embarrassed now :)).

Here's my attempt in using int():

from anygui import *

def handler(**kw):
    a = txt.text
    b = txt2.text
    int(a)
    int(b)
    lbl.text = a + b

mywin = Window()
mywin.size = 400, 200
mywin.title = "test 1.0"
mywin.layout = Placer()
app = Application()
app.add(mywin)

txt = TextField()
txt.position = 10, 10
txt.size = mywin.width - 20, 25
mywin.add(txt, top=10, left=10, right=100, hstretch=1)

txt2 = TextField()
txt.position = 10, 10
txt.size = mywin.width - 100, 25
mywin.add(txt2, top=70, left=10, right=100, hstretch=1)

btn = Button()
btn.text = "Zbroji!"
btn.width = mywin.width - 50
mywin.add(btn, top=9, left=mywin.width - 70, right=10)
link(btn, 'click', handler)

lbl = Label()
lbl.txt = "rezultat"
lbl.position = 50, 100
mywin.add(lbl)

app.run()

Note that this error was encountered:
the numbers were concatenated instead of added (so I got a result of 32
instead of 5, etc.).

Thanks for your help! :)

"Peter Hansen" <peter at engcorp.com> wrote in message
news:3D6B68D6.EBB57001 at engcorp.com...
> Nikola Plejic wrote:
>
> > I tried using int() but that doesn't seem to work.
>
> If you ever find yourself typing something like this, STOP,
> back up, and type this instead:
>
>    Here's my attempt using int():
>
>    [insert your code here, cut and pasted so there are no typos]
>
>    Note the exception that was raised:
>
>    [insert full Python traceback here, cut and pasted]
>
>    I don't understand what it's telling me, so can someone
>    please explain?
>
> That will generally solve your problem quickest. <wink>
>
> -Peter





More information about the Python-list mailing list