My list was a little off. A revised example here still doesn’t work properly, even after fixing the logical list to be the exact same as the displayed list. The hard-coded button to change the text on is 1,2 and it changes 4,2. However, as the debug info clearly prints during Frame initialization, the button at self.cells[1][2] has the text “x:1,y:2”. Later during the use of the OnButton method it’s different.
Also, I still have the problem that if you use the 2 commented lines to create and event bind the button instead of the lines immediately below them, then the button event won’t ever fire at all.
#!/usr/bin/python
import wx
class MyFrame(wx.Frame):
…def init(self,*args,**kwargs):
…wx.Frame.init(self,*args,**kwargs)
…self.cells = [[0,]*7]*5
…siz = wx.GridSizer(7,5,0,0)
…for y in xrange(7):
…for x in xrange(5):
…if (x,y) == (0,0):
…#self.cells[0][0] = wx.Button(self,wx.NewId(),“button”)
…self.button = wx.Button(self,wx.NewId(),“button”)
…self.cells[0][0] = self.button
…else:
…self.cells[x][y] = wx.Button(self,wx.ID_ANY,“x:%s,y:%s”%(x,y))
…print x,y," ",self.cells[x][y].GetLabel()
…siz.Add(self.cells[x][y],0,wx.EXPAND)
…self.SetSizer(siz)
…#self.Bind(wx.EVT_BUTTON,self.OnButton,self.cells[0][0])
…self.Bind(wx.EVT_BUTTON,self.OnButton,self.button)
…def OnButton(self,evt=None):
…print “Label Was:”,self.cells[1][2].GetLabel()
…self.cells[1][2].SetLabel(“Click”)
class MyApp(wx.App):
…def OnInit(self):
…frame = MyFrame(None)
…frame.Show(True)
…self.SetTopWindow(frame)
…return True
def main():
…app = MyApp(0)
…app.MainLoop()
if name == “main”:
…main()