changing numbers to spellings

Steve Holden steve at holdenweb.com
Sun Oct 1 01:06:45 EDT 2006


flyingisfun1217 at gmail.com wrote:
> Hey,
> 
> Sorry to bother everybody again, but this group seems to have quite a
> few knowledgeable people perusing it.
> 
> Here's my most recent problem: For a small project I am doing, I need
> to change numbers into letters, for example, a person typing in the
> number '3', and getting the output 'Three'. So far, I have an interface
> that only collects numbers (or letters), and displays them in a text
> variable label (as you can see below). Heres the code I have:
> 
> +--------------------------------+-----------------------------------+
> 
> var=StringVar()
> 
> def collect():
>      var.set(entrybox.get())
> 
> spelledentry=Label(root, textvariable=var)
> spelledentry.grid(row=5, column=1)
> 
> filler1=Label(root, text="                    ")
> filler1.grid(row=0, column=0)
> 
> titletext=Label(root, text="NumberSpeller2")
> titletext.grid(row=0, column=1)
> 
> filler2=Label(root, text="                    ")
> filler2.grid(row=0, column=2)
> 
> filler3=Label(root, text="\n")
> filler3.grid(row=1, column=0)
> 
> entrybox=Entry(root)
> entrybox.grid(row=1, column=1, sticky=N)
> 
> enterbutton=Button(root, text="Spell!", command=collect)
> enterbutton.grid(row=3, column=1, sticky=N)
> 
> filler4=Label(root, text="")
> filler4.grid(row=4, column=1)
> 
> filler5=Label(root, text="")
> filler5.grid(row=6, column=1)
> 
> website=Label(root, text="Visit the NS2 Website")
> website.grid(row=7, column=1, sticky=S)
> 
> +-------------------------------------+----------------------------------------+
> 
> Like I explained a little before, I need to keep users from entering
> any letters, and I need to have the numbers they typed in translated to
> text.
> 
> Can someone explain how I could go across doing this?
> 
You should get some clue about the number conversion (not to menion a 
bunch of code you can lift :) from

     http://www.python.org/pycon/dc2004/papers/42/ex1-C/num2eng.py

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd          http://www.holdenweb.com
Skype: holdenweb       http://holdenweb.blogspot.com
Recent Ramblings     http://del.icio.us/steve.holden




More information about the Python-list mailing list