[Tutor] wxPython buttons in a loop (original) (raw)

adam adam at monkeez.org
Thu Jul 29 11:46:47 CEST 2004


I'm trying to create a wxPython app which goes through a loop and produces a wxBitmapButton for every letter of the alphabet.

However, when I run the code below, I get three a's duplicated, although the debugging print statements show that 'alphabet_graphics/b.bmp' has also been called.

Is this problem related to bmp being a constant here? If so, how would I go about overwriting it? I tried creating a list of 'bmp' but I always got IndexError: list index out of range when I ran it.

Any help gratefully appreciated.

Adam

alphabet = ['a','b','c'] alphabetgraphics = ['a.bmp', 'b.bmp', 'c.bmp'] #bmp =[] # Not currently used #grafic = [] # Not currently used

    for i in range(len(alphabet)):
        print alphabetgraphics[i] # Debug tool.
        bmp = wxBitmap('alphabet_graphics/' + alphabetgraphics[i],

wxBITMAP_TYPE_BMP) self.grafic =wxBitmapButton(self,30,bmp,wxPoint(160,20), wxSize(bmp.GetWidth()+10,bmp.GetHeight()+10)) self.sizer2.Add(self.grafic,1,wxEXPAND) print bmp # Debug tool.



More information about the Tutor mailing list