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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:01:53+00:00 2026-05-27T13:01:53+00:00

So I am trying to do some very basic things in pygame. It is

  • 0

So I am trying to do some very basic things in pygame. It is my first few days using it so I am a beginner. I am trying to change the color of something whenever I press it with the mouse. I know how to change the colors by timing which is what I have my code down below. I am trying to change the color of the cloud in my code below, if you run it you will see the cloud is the top left and I have it changing between white and black every three seconds but I want it to change based on mousebuttondown. Thanks

import pygame, time, sys
from pygame.locals import *

def drawItem(windowSurface, x, y):
    pygame.draw.polygon(windowSurface, RED, ((0+x, 100+y),(100+x, 100+y), (50+x, 50+y)))
    pygame.draw.polygon(windowSurface, GREEN, ((0+x,100+y),(100+x,100+y),(100+x,200+y),(0+x,200+y)))


pygame.init()

windowSurface = pygame.display.set_mode((500, 400), 0, 32)
pygame.display.set_caption("Lab 9")

BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
GRASS = (26, 82, 26)
SKY = (179,237,255)

color = SKY
flag = False

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

    windowSurface.fill(SKY)

    drawItem(windowSurface,200,120)
    pygame.draw.rect(windowSurface, GRASS, (0,300,500,500),0)

    house = ((0+50, 100+50),(100+50, 100+50), (50+50, 50+50), (50+100, 50+100))

    for i in range(3):
        pygame.draw.circle(windowSurface,color, house[i], 80)  

    if flag == False:
        color = WHITE
        flag = True
    elif flag == True:
        color = BLACK
        flag = False

    pygame.display.update()
    time.sleep(3)
  • 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-27T13:01:54+00:00Added an answer on May 27, 2026 at 1:01 pm

    You’ve already discovered how to test for the type of an event (checking whether event.type == QUIT).

    You can extend this to check whether it’s a mouse button click. Stick this in your for event in pygame.event.get() loop:

    if event.type == MOUSEBUTTONDOWN:
        flag = not flag # This will swap the value of the flag
    

    Then get rid of the flag = True and flag = False lines below, since you don’t need them anymore. Also get rid of the time.sleep() call; or at least change it to a reasonable frame rate (like time.sleep(0.2) = 50 frames per second).

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

Sidebar

Related Questions

I'm trying to do some very basic time math - basically, given inputs of
I'm trying to decide how to implement a very basic licensing solution for some
I am trying something very simple, but for some reason it does not work.
I'm trying to do a very simple INSERT using VB.NET. For some reason I'm
I'm trying to use System.Diagnostics to do some very basic logging. I figure I'd
I'm trying to do very basic, custom animation with JavaScript. I'm using a library
I am facing a very basic problem. Some time small things can take your
I'm trying to make a very basic image creator using PySide. But I'm having
I am trying to do some very simple form validation checking for null or
I was trying to look through some very old FORTRAN code and came across

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.