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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:51:16+00:00 2026-05-24T07:51:16+00:00

I am creating a simple mp3 player and my first task was to create

  • 0

I am creating a simple mp3 player and my first task was to create a simple button that a user could press. I created a class called Button which handled this behavior and detects if a user has clicked it and then changes color. I am now trying to have a default text that the button displays and another string (pres_string) which will be displayed if the button is being pressed.

The only problem is my background surface seems to be in the wrong place and is drawing over any changes I have made.

Here is my code:

http://pastebin.com/Nh3yy01X

As you can see I’ve commented out the lines I described and tried it with basic variables in the main function just to test what was going wrong.

Thanks for any help.

(Feel free to change the title of the question, I wasn’t sure what most accuratelydescribed my problem)

  • 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-24T07:51:17+00:00Added an answer on May 24, 2026 at 7:51 am

    Clear the surface every loop

    def draw(self):
        # clear screen."
        self.screen.fill( self.color_bg )
    
        # first draw background
        # Then buttons
        # then any extra top level text
    
        # update
        pygame.display.flip()
    

    tip: For colors, you can call pygame.Color() with human-names like red ( gray20 and gray80 have a nice contrast, to use for bg and text. )

        from pygame import Color
        text = Color('gray20')
    

    Your button, psuedocode. Fix: moved color as an instance member.

    class Button(object):
        def __init__(self, text, rect=None):
            self.color_bg = Color("gray20")
            self.color_text = color("gray80")
    
            if rect is None: rect = Rect(0,0,1,1)
            self.rect = rect
            self._render()   
        def _render(self):
            # draw button and .render() font, cache to surface for later.    
            self.surface_cached = self.surface.copy()
            # render text
    
            #if size changes, save rect.size of cached surface , mantaining location
            self.rect.size = cache.get_rect.size
        def draw(self):
            # draw cached surface
            screen.blit( self.surface_cached, self.rect)
    

    For testClick use Rect.collidepoint http://www.pygame.org/docs/ref/rect.html#Rect.collidepoint

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

Sidebar

Related Questions

I'm creating a simple API that creates typed classes based on JSON data that
I'm creating a simple tag system that allows me to link a tag to
The issue is simple really. Instead of creating folders in Visual Studio, I create
Creating a simple public/private keypair, such as through ssh-keygen does not create a file
I'm creating a simple GUI form with one button in IntelliJ IDEA 9. The
I'm creating a simple query builder for PHP PDO, to create queries faster, without
I am creating a simple game designed to prompt the user for the Greek
I'm struggling with creating a simple one-to-many relationship using Code First in EF. I
I am using Visual Studio 2008 Express and I tried creating a simple console
One simple method I've used in the past is basically just creating a second

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.