[Tutor] String to integer?

adam adam at monkeez.org
Wed Sep 1 14:54:28 CEST 2004


I have a list which holds all the letters of the alphabet. I want to
create a button (wxPython) for each of these letters and then give the
button an ID (count - which is an integer). However, I would like the ID
to be driven by the list (which is string). See code below.

What's the easiest way of creating an integer which is based on a value of
a letter? I really don't mind if it was based on the ascii code, or
another equivalent.

Thanks in advance.

Adam

alphabet = ['a','b','c','d','e' ... and so on.
for i in alphabet:
    count = count + 1
    bmp = wxBitmap('alphabet_graphics/' + i + '.bmp', wxBITMAP_TYPE_BMP)
    self.grafic =wxBitmapButton(self, count,bmp,wxPoint(160,20),
wxSize(bmp.GetWidth()+10,bmp.GetHeight()+10))
    self.sizer2.Add(self.grafic,1,wxEXPAND)
    EVT_BUTTON(self, count, self.ButtonPushed)




More information about the Tutor mailing list