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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:21:20+00:00 2026-06-07T08:21:20+00:00

I’ve found lots of tutorials for using pygame, and its font library, but they

  • 0

I’ve found lots of tutorials for using pygame, and its font library, but they all show the same exact thing. They all show you how to write some plain text on to a background, which is great, but going beyond that there’s not a lot of useful information that I’ve found.

With the project I’m working on, I have menu buttons that I’ve implemented as sprites. When you hover over them they change colors, and that all works pretty well. What I’d like to do is write text on these buttons, but I’m baffled on how to do that. From the docs font.render works as so:

“This creates a new Surface with the specified text rendered on it. Pygame provides no way to directly draw text on an existing Surface: instead you must use Font.render – draw text on a new Surface to create an image (Surface) of the text, then blit this image onto another Surface.”

So I’ve tried to take the image that’s attached to my sprite and directly blit my text onto that. That seems to mostly do absolutely nothing:

    resume = self.button_font.render(
        'Resume Game',
        True,
        constants.WHITE,
        (23, 56, 245) # Main color of the button, tried without this as well
    )
    self.resume_button.image.blit(
        resume,
        self.resume_button.rect,
    )

I know that code runs, but you never see any text. If I blit the text directly to my main screen surface, it’ll just write over the top of my resume button (depending on the blit order of course). What am I doing wrong? The docs seem to indicate that this is the right way to handle it, but I’ve yet to find anyone else doing this. Any help would be greatly appreciated.

  • 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-07T08:21:22+00:00Added an answer on June 7, 2026 at 8:21 am

    Did you call convert on the surface of your Sprite? If not, better do so.

    Having different pixel formats on your surfaces will lead to all kind of annoying and hard to understand bugs.


    Example:

    import pygame
    
    pygame.init()
    screen = pygame.display.set_mode((400, 400))
    image = pygame.image.load('1.png')
    
    sprite = pygame.sprite.Sprite()
    sprite.image = image
    sprite.rect = image.get_rect()
    
    font = pygame.font.SysFont('Sans', 50)
    text = font.render('This is a text', True, (255, 0, 0))
    
    sprite.image.blit(text, sprite.rect)
    
    group = pygame.sprite.Group()
    group.add(sprite)
    group.draw(screen)
    
    pygame.display.flip()
    
    print 'bits per pixel:'
    print 'image', image.get_bitsize()
    print 'screen', screen.get_bitsize()
    

    This will lead to the following bug:

    without convert

    Output:

    bits per pixel
    image 8
    screen 32
    

    Now change the line

    image = pygame.image.load('1.png')
    

    to

    image = pygame.image.load('1.png').convert()
    

    and everything will be fine:

    with convert

    Output:

    bits per pixel
    image 32
    screen 32
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am using Paperclip to handle profile photo uploads in my app. They upload
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.