Newbie question on how to determine which button clicked?

Hi Chipp,

In your "OnLaunchScript" function, replace your lines of code with these:

button_object = event.GetEventObject()
button_label = button_object.GetLabel()
wx.MessageBox(button_label,"TITLE",wx.OK|wx.ICON_INFORMATION,self)

I found that neat trick here: http://blog.genotrance.com/2006/09/30/wxpython-widgets-part-ii/

Mike

···

-----Original Message-----
From: Chipp Walters [mailto:chipp@chipp.com]
Sent: Sunday, April 08, 2007 1:22 AM
To: wxpython-users@lists.wxwidgets.org
Subject: Newbie question on how to determine which button clicked?

Hi, just starting with wxPython. I've got a very small PySimpleApp which reads files from a folder and creates a button for each file.
The problem is below in the "OnLaunchScript" function, I don't know how to tell which button was clicked on. Any help?

Thanks, Chipp

The code:

import wx

class InsertFrame(wx.Frame):

    def __init__(self, parent, id):
        wx.Frame.__init__(self, parent, id, 'altToolbar', size=(300,400))
        panel = wx.Panel(self)

        tYpos=50

        for i in range(0,tBtnCount):
            self.tNewBtn = wx.Button(panel, label=tBtns[i],
pos=(10,tYpos),size=(150,40))
            self.Bind(wx.EVT_BUTTON, self.OnLaunchScript, self.tNewBtn)
            tYpos+=50

    def OnLaunchScript(self, event):
        tMsg = str(self.tNewBtn.Label)
        wx.MessageBox(tMsg,"TITLE",wx.OK|wx.ICON_INFORMATION,self)

if __name__ == '__main__':

    tBtns = ["one","two","three"]
    tScripts = ["oneFile","twoFile","threeFile"]
    tBtnCount = len(tBtns)
    tFileCount = len(tScripts)

    app = wx.PySimpleApp()
    frame = InsertFrame(parent=None, id=-1)
    frame.Show()
    app.MainLoop()