I'd like to get an index value as a button event

I’d like to get the index as a button event like the code above.