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 8402675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:07:56+00:00 2026-06-09T22:07:56+00:00

I am a beginner in python, and I’m trying to draw a circle wherever

  • 0

I am a beginner in python, and I’m trying to draw a circle wherever the mouse is(I also have a mouse and background image). Here is my code:

while True:

    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit

        if event.type == MOUSEBUTTONDOWN:
            color = (100,100,100)
            posx,posy = pygame.mouse.get_pos()
            screen.lock()
            pygame.draw.circle(screen, color, (posx,posy), 50)
            screen.unlock()

    screen.blit(background,(0,0))
    x,y = pygame.mouse.get_pos()
    x -= mousec.get_width()/2
    y -= mousec.get_height()/2

    screen.blit(mousec, (x,y))

    pygame.display.update()

Whenever I click nothing happens. Why doesn’t it draw a circle? Thanks for the help!

  • 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-09T22:07:57+00:00Added an answer on June 9, 2026 at 10:07 pm

    I know almost nothing about pygame so I can’t be much more help than this… but what I think you are doing is always drawing back over your circle. Try this out:

    pygame.init()
    screen = pygame.display.set_mode((640, 480))
    
    screen.fill((0,0,0))
    
    while True:
    
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
    
            if event.type == MOUSEBUTTONDOWN:
                # draw background first (however)
                screen.fill((0,0,0))
    
                # draw your other layers (mouse image)
    
                # draw the circle
                color = (255,255,255)
                posx,posy = pygame.mouse.get_pos()
                pygame.draw.circle(screen, color, (posx,posy), 50)
    
        pygame.display.update()
    

    Basically what is happening in your example is that when you mouse down event does a draw, you will then draw back over it again with the background. I am not sure what mousec is but that will be drawn over the background every time. So you will never see a circle drawn from your mouse click

    My example fills the background once to start, and then when there is a mouse down, it will fill the background again to draw over the previous state, and then draw the circle.

    Another approach, using your exact example, is to only record the mouse position when checking the event, and defer the drawing of the circle until after your layers. You would “remember” the last mouse position to constantly redraw that circle on every loop:

    last_mouse_pos = None
    
    while True:
    
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit
    
            if event.type == MOUSEBUTTONDOWN:
                last_mouse_pos = pygame.mouse.get_pos()
    
            elif event.type == KEYDOWN and event.unicode == 'c':
                # clear the circle when pressing the 'c' key
                last_mouse_pos = None
    
        screen.blit(background,(0,0))
        x,y = pygame.mouse.get_pos()
        x -= mousec.get_width()/2
        y -= mousec.get_height()/2
    
        screen.blit(mousec, (x,y))
    
        if last_mouse_pos:
            color = (100,100,100)
            posx,posy = last_mouse_pos
            pygame.draw.circle(screen, color, (posx,posy), 50)
    
        pygame.display.update()
    

    The difference in this approach is that you are always drawing everything on each loop as opposed to only in response to changes in events.

    Update

    In response to your question in the comments… a way to modify that second example to retain all the mouse clicks would be to save them up in a set and draw them back each time.

    mouse_clicks = set()
    
    while True:
    
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit
    
            if event.type == MOUSEBUTTONDOWN:
                mouse_clicks.add(pygame.mouse.get_pos())
    
            elif event.type == KEYDOWN and event.unicode == 'c':
                # clear the circle when pressing the 'c' key
                mouse_clicks.clear()
    
        screen.blit(background,(0,0))
        x,y = pygame.mouse.get_pos()
        x -= mousec.get_width()/2
        y -= mousec.get_height()/2
    
        screen.blit(mousec, (x,y))
    
        for pos in mouse_clicks:
            color = (100,100,100)
            posx,posy = pos
            pygame.draw.circle(screen, color, (posx,posy), 50)
    
        pygame.display.update()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Python beginner here, I have a list of lists and want to refer to
Python beginner here. I have a text file that is sorted into columns: fields
I am a beginner with Python and trying few programs. I have something like
I am a beginner in Python and I have written this simple code but
beginner to python here. I have 2 nested lists that I want to merge:
I am a beginner at python (one week). Here I am trying print the
I'm a beginner using python 3.2 and i have a book whos code is
As part of the last assignment in a beginner python programing class, I have
I'm a Python beginner and have just started using packages. When you're calling a
I am a beginner of Python. I am trying now figuring out why the

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.