How can I detect buttons in a GUI of an app with pattern detection using python?
First, have a look at the squares.py sample provided by OpenCV. It should handle a fair number of button types with some tweaking.

Here is the output I got (with some tweaking) for your Calculator example:


I made the following tweaks to the squares application:

Change this code (starting on line 84):

if(result.total == 4 and 
   abs(cv.ContourArea(result)) &gt; 1000 and 
   cv.CheckContourConvexity(result)):


To this:

if(result.total == 4 and 
   abs(cv.ContourArea(result)) &lt; 1300 and 
   abs(cv.ContourArea(result)) &gt; 300 and
   cv.CheckContourConvexity(result)):


Also, since you don't have to worry about scale or rotation variations, check out using matchTemplate. Also, its corresponding tutorial (in C++) is here.

See my other answer for another example of how template matching works. Also, you might find this answer helpful for detecting the top X matches with matchTemplate.

Hope that helps!