Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6769565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:12:31+00:00 2026-05-26T15:12:31+00:00

I am working on a project within Python that is to determine the multi-tasking

  • 0

I am working on a project within Python that is to determine the multi-tasking efficiency of a person. Part of the project is to have a user respond to an event on screen using the mouse. I have decided to have the user click within a ball. However I am having issues with my code on verifying that the mouse cursor is actually within the confines of the circle.

The code for the methods in question are below. Radius of the circle is 10.

    #boolean method to determine if the cursor is within the position of the circle
    @classmethod
    def is_valid_mouse_click_position(cls, the_ball, mouse_position):
        return (mouse_position) == ((range((the_ball.x - 10),(the_ball.x + 10)), 
                                 range((the_ball.y + 10), (the_ball.y - 10))))

    #method called when a pygame.event.MOUSEBUTTONDOWN is detected.
    def handle_mouse_click(self):
    print (Ball.is_valid_mouse_click_position(self.the_ball,pygame.mouse.get_pos))

No matter where I click within the circle, the boolean still returns False.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:12:31+00:00Added an answer on May 26, 2026 at 3:12 pm

    I don’t know pygame, but perhaps you want something like this:

    distance = sqrt((mouse_position.x - the_ball.x)**2 + (mouse_position.y - the_ball.y)**2)
    

    This is the standard distance formula to get the distance between the mouse position and the center of the ball. Then you’ll want to do:

    return distance <= circle_radius
    

    Also, for sqrt to work, you’ll need to go from math import sqrt

    NOTE: you could do something like:

    x_good = mouse_position.x in range(the_ball.x - 10, the_ball.x + 10)
    y_good = mouse_position.y in range(the_ball.y - 10, the_ball.y + 10)
    return x_good and y_good
    

    which is more along the lines of what you have written – but that gives you an allowable area which is a square. To get a circle, you need to calculate distance as shown above.

    NB: My answer assumes that mouse_position has properties x and y. I don’t know if that’s actually true because I don’t know pygame, as I mentioned.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a fully working Setup project within Visual Studio 2008 that takes inputs
I have Aptana installed within Eclipse. I'm working on a project with the dojo
I am working on implementing Zend Framework within an existing project that has a
I am working a project that does not have a trunk / branches /
I am working on a database project within VS2010. I have created a few
I currently am working on a project within Crystal Reports that refuses to use
I'm working on a project using Maven as tool. Within the project I have
I working on project and have problem with threading and update of UI. I
I'm currently working on project with Haskell, and have found myself some trouble. I'm
I'm working on project that lets users choose some scientific authors and columnists and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.