# Find out what word you are hovering mouse over

I want to be able to pop up something when the user hovers over particular words that are on a label in pygame.

Can anyone give me a good (or even bad) idea on how to implement this (doesn't have to be pygame specific)? Do I have to put each word in a different label and place them one after the other?

(what I'm calling a label is the result of font.render)

• How are you drawing this label? With Font.render? – user14497 Oct 3 '12 at 2:58
• Yeah sorry, what I'm calling a label is the result of font.render – Olivier Oct 3 '12 at 3:17

When you use Surface.blit(), a rectangle is returned which you can associate with your label. You could consider keeping a list of these, or a list of tuples of the returned Rect and the text or label callback. In your main loop, you can iterate over this list and call Rect.collidepoint(pygame.mouse.get_pos()) to find out if the mouse is in the current iteration step's Rect.
• Yeah, you don't need to hang on to the surface created by Font.render(), you just need the Rect that the blit operation returns, so this shouldn't add too much overhead. Alternatively, you can take a look at Font.metrics, but I think having to parse the list returned from that would be more work than it was worth. – user14497 Oct 3 '12 at 3:45