Mouse X & Y positions for get_rect.collidepoint in pygame
<p>I am trying to create a click event in PyGame but I am facing an error:</p>

<pre class="lang-none prettyprint-override"><code>AttributeError: 'NoneType' object has no attribute 'get_rect'
</code></pre>

<p>The code:</p>

<pre><code>mouse_pos = pygame.mouse.get_pos()
mouse_pressed = pygame.mouse.get_pressed()

if mouse_pressed[0] and play_btn.get_rect().collidepoint(mouse_pos[0],
                                                         mouse_pos[1]):
    print "Mouse clicked play"
</code></pre>

<p>The button...</p>

<pre><code>play_btn = button("PLAY NOW", 210, 150, 300, 80, white, grey)
</code></pre>

<p>Based on the information provided, <code>button</code> doesn't return anything. It returns <code>None</code>.</p>

<p>According to your previous <a href="http://stackoverflow.com/questions/39190253/pygame-button-cant-seek-in-this-data-source">question</a> your function <code>button</code> looks like this:</p>

<pre><code>def button(btn_txt_img,posx,posy):
    btn_txt_img = pygame.image.load(("/Users/wolf/Desktop/python/img/",btn_txt_img,".png")).convert_alpha()
    btn_txt_img_hover = pygame.image.load(("/Users/wolf/Desktop/python/img/",btn_txt_img,"_hover.png")).convert_alpha()

    if((w_size[0]/3.3)+btn_txt_img.get_rect().width &gt; mouse_pos[0] &gt; (w_size[0]/3.3) and posy+btn_txt_img.get_rect().height &gt; mouse_pos[1] &gt; posy):
        return main_screen.blit(btn_txt_img_hover, [(w_size[0]/3.3),posy,btn_txt_img.get_rect().width,btn_txt_img.get_rect().height])
    else:
        return main_screen.blit(btn_txt_img, [(w_size[0]/3.3),posy,btn_txt_img.get_rect().width,btn_txt_img.get_rect().height])
    pygame.display.update()
</code></pre>

<p>Blitting works directly on the object and therefore returns <code>None</code>. Since your function returns whatever <code>main_screen.blit...</code> returns, it'll also return <code>None</code></p>

python pygame