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

  • SEARCH
  • Home
  • 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 8102521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:15:45+00:00 2026-06-05T23:15:45+00:00

I am trying to have an onclick button print a check and run my

  • 0

I am trying to have an onclick button print a check and run my pencil function. At the moment if I hover over the Box sprite.. it will run the print and pencil function. It should be ONCLICK it runs those 2. Can anyone help me out? Thanks! (this should be all relevant code, if you need more please let me know 🙂

class Box(pygame.sprite.Sprite):
def __init__(self):
    pygame.sprite.Sprite.__init__(self)
    self.image = pygame.Surface((35, 30))
    self.image = self.image.convert()
    self.image.fill((255, 0, 0))
    self.rect = self.image.get_rect()
    self.rect.centerx = 25
    self.rect.centery = 505
    self.dx = 10
    self.dy = 10

while keepGoing:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            keepGoing = False
        box = Box()
        allSprites = pygame.sprite.Group(box)   
        allSprites.draw(screen)

        if event.type == MOUSEMOTION:
            x,y = event.pos
            if box.rect.collidepoint(x,y) and pygame.MOUSEBUTTONUP:                      
                print("collide works")
                pencil(background,clock,keepGoing,screen)
        pygame.display.flip()
  • 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-06-05T23:15:46+00:00Added an answer on June 5, 2026 at 11:15 pm

    Your code is not checking for mouse clicks, but rather mouse movement.

    If you want to be testing for a click on your box, change condition to check for MOUSEBUTTONDOWN or MOUSEBUTTONUP events (depending on what part of the click you want to react to), rather than MOUSEMOTION events.

    There are some other issues with your code though. For instance, you’re creating your Box and Group after every event. Probably you want to just create them once, before going into the game loop (this will both make more sense and perform better).

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

Sidebar

Related Questions

I have a simple button in HTML like this: <input type='button' id='btnPrint' value='Print' onclick=changeStylesheet();
I am trying to have a text box resize on click. in the head:
I am trying to have a method that takes in a username and will
I have the worlds most simple javascript function: fnSubmit() { window.print(); document.formname.submit(); } Which
I'm trying to add a custom printing button (like print invoice) on the Sales
Trying my hand at java and android and have run into a problem which
I've created a like button for my users posts. I'm trying to print out
I have the following code that will count the elapsed time and print the
I am trying to fire a javascript by onclick event of submit button but
I am trying to print Hello + written text in text box (As I

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.