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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:32:17+00:00 2026-05-31T22:32:17+00:00

I am using python 2.7.1 with pygame 1.9.1 on 64-bit win7. I am using

  • 0

I am using python 2.7.1 with pygame 1.9.1 on 64-bit win7. I am using the gradient code from http://www.pygame.org/wiki/GradientCode to draw my background. I then display text like so:

countText = font.render( "%d" % secs_left, 1, (255, 0, 0))
countRect = countText.get_rect()
countRect.y, countRect.centerx = yPos, screen.get_rect().width/2
screen.blit(countText, countRect)
pygame.display.flip()

I use this to display a countdown timer, but the problem is the numbers draw on top of one another. I can specify a background color in the font.render() call that will solve this, but then I get another problem where the solid background doesn’t match the gradient background.

I think this can be solved by saving a copy of the gradient background in another surface, and then drawing the relevant portion of the saved surface onto the background before drawing the next number, but I am not sure how to do this.

I can save a copy of the gradient background like this:

# save a surface with same size and gradient as background
bg_image = pygame.Surface(screen.get_size())
fill_gradient(bg_image, BG_COLOR, GRADIENT_COLOR)

But how do I select the relevant portion of bg_image and draw it to my main screen background? I tried something like this, doing a screen.blit() to try and erase the current countdown number before blitting the new number, but it doesn’t work:

countText = usefont.render( "%d" % secs_left, 1, (255, 0, 0))
countRect = countText.get_rect()
countRect.y, countRect.centerx = yPos, screen.get_rect().width/2
screen.blit(bg_image, (0,0), countRect)
screen.blit(countText, countRect)
pygame.display.flip()

Would this be the best approach (with code that works)? Or is there a better way to do this?

Thanks for your 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-05-31T22:32:18+00:00Added an answer on May 31, 2026 at 10:32 pm

    I can use Surface.set_clip() to restrict the area being updated to just the rectangle containing the countdown text:

    countText = usefont.render( "%d" % secs_left, 1, (255, 0, 0))
    countRect = countText.get_rect()
    countRect.y, countRect.centerx = yPos, screen.get_rect().width/2
    screen.set_clip(countRect)        # Allow updates only to area in countRect
    screen.blit(bg_image, (0,0))      # bg_img will only be drawn within countRect
    screen.blit(countText, countRect)
    pygame.display.flip()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to bind two windows from seprate processes together using Python/Pygame?
Is there a way I can display text on a pygame window using python?
I'm currently trying to write a multiple-file Python (2.6.5) game using PyGame. The problem
I am trying to make a simple drawing program in python using pygame. I
I am working on a project in python using pygame and pyro. I can
I'm using Python 2.7 and Pygame 1.9.1 The fact that there are a few
I'm using Python 2.7 and Pygame but any language answer will do. I'm trying
I am using python and I am trying to use the set_colorkey function from
I've made a pathfinding visualizer using python and pygame. As of now, it can
I'm working on an adventure game in Python using Pygame. My main problem is

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.