title: Why’s My “‘Start’ Button Display Text” Only Appearing after I’d Click the Center of My Screen or Tap Return via My Keyboard? And How Can I Fix This?
body: <p>Why's My &quot;'Start' Button Display Text&quot; Only Appearing after I'd Click the Center of My Screen or Tap Return via My Keyboard? And how can I fix this?</p>
  <p>Before, I'd been experiencing trouble getting my &quot;'Start' button display text&quot; to disappear either after &quot;'left-clicking' it with my 'mouse'&quot; or &quot;'pressing' 'return' via my keyboard.&quot; I'd only been able to initiate the enemy sprites &quot;after&quot; clicking on the &quot;'Start' button display text&quot; on the screen or tapping the return key on my keyboard through the logic within my program's main loop.</p>
  <p>Here're the codes for my program (Thank you for your time and help!):</p>
  <pre><code># |---------------------------------------------------------------------------------------------------------|
  # |                              | This Is a BASIC INTRODUCTORY GAME DESIGN! |                              |
  # |---------------------------------------------------------------------------------------------------------|
  
  import random
  
  import pygame
  from pygame.locals import (K_UP, K_DOWN, K_LEFT, K_RIGHT, K_ESCAPE, KEYDOWN, K_RETURN, QUIT)
  
  
  # |---------------------------------------------------------------------------------------------------------|
  # |                 | &quot;DEFINING&quot; the Program's &quot;ELEMENTS:&quot; &quot;COMPONENTS&quot; and &quot;MECHANICS!!&quot; |                 |
  # |---------------------------------------------------------------------------------------------------------|
  
  # &quot;'Define' the ''player' object' by ''extending' 'pygame.sprite.Sprite;'' The 'new 'Surface' sprite' that
  # will be ''drawn' on the 'screen'' will be 'attributed 'as' the 'player:''&quot;
  class Player(pygame.sprite.Sprite):
  
      # This--def __init__(self, color, width, height)--is a &quot;Constructor;&quot; &quot;Constructors&quot; are used to
      # &quot;''initialize ('Assign 'values--like collections of statements (i.e 'instructions')'')' to the
      # 'data member' of a 'class'' when an ''object' of the 'class'' is 'created.'&quot;
      def __init__(self):
  
          # &quot;super(Player, self).__init__()&quot; is equivalent to &quot;base class,&quot; &quot;pygame.sprite.Sprite.__init__(self).&quot;
          # This will use the &quot;super()&quot; method to call the &quot;__init__()&quot; constructor of &quot;Sprite.&quot; &quot;super()&quot; is
          # typically used for the &quot;'inheritance' of 'classes'&quot; in &quot;OOP ('Object-Oriented Programming').&quot; They
          # &quot;'expands' the 'functionality' of an ''inherited' method' or more through 'permissible access' to a
          # ''parent' and or 'sub' class:'&quot;
          super(Player, self).__init__()
  
          # &quot;'Create' a 'new ''imaged' surface (I.e., 'Jet.png')'' and then create a 'transparent' copy of its
          # 'surface' with the 'desired' 'pixel format' 'through' the 'convert_alpha()' command:&quot;
          self.The_Surface = pygame.image.load(&quot;Jet.png&quot;).convert_alpha()
  
          # &quot;Scale&quot; the image:
          self.The_Surface = pygame.transform.scale(self.The_Surface, size=(920 / 11, 550 / 11))
  
          # &quot;'Create' a 'new 'rectangular 'sprite'' 'on' the 'surface (Or 'image')' 'of' the 'display:'&quot;
          self.rect = self.The_Surface.get_rect()
  
      # &quot;'Move' the 'sprite' 'based upon' the ''keys' 'that are 'pressed''' by the 'player'&quot; on their
      # keyboard&quot; and &quot;secure&quot; their &quot;object&quot; on the display window:
      def update(self, pressed_keys):
  
          if self.rect.left &gt; 0 and pressed_keys[K_LEFT]:
              self.rect.move_ip(-17, 0)
  
          if self.rect.right &lt; 800 and pressed_keys[K_RIGHT]:
              self.rect.move_ip(17, 0)
  
          if self.rect.top &gt; 0 and pressed_keys[K_UP]:
              self.rect.move_ip(0, -17)
  
          if self.rect.bottom &lt; 600 and pressed_keys[K_DOWN]:
              self.rect.move_ip(0, 17)
  
  
  # &quot;'Define' the ''enemy' object' by ''extending' 'pygame.sprite.Sprite;'' The 'new 'Surface' sprite' that
  # will be ''drawn' on the 'screen'' will be 'attributed 'as' the 'enemy:''&quot;
  class Enemy(pygame.sprite.Sprite):
  
      def __init__(self):
          super(Enemy, self).__init__()
  
          # &quot;'Create' a 'new ''imaged' surface (I.e., 'Missile.png')'' and then create a 'transparent' copy of
          # its 'surface' with the 'desired' 'pixel format' 'through' the 'convert_alpha()' command:&quot;
          self.The_Surface = pygame.image.load(&quot;Missile.png&quot;).convert_alpha()
  
          # &quot;Scale&quot; the image:
          self.The_Surface = pygame.transform.scale(self.The_Surface, size=(310 / 8, 230 / 8))
  
          # &quot;'Create' 'new 'Missile.pngs' at ''random' locations 'along' the 'right edge' of the
          # 'screen' and ''centered' 'off'' of it:'''&quot;
          self.rect = self.The_Surface.get_rect(center=(random.randint(800, 900), random.randint(0, 600)))
  
          # &quot;Define a 'random number' 'between '5' and '20.''&quot; This will &quot;specify 'how fast' the 'enemy'
          # 'moves towards' the 'player:'&quot;
          self.speed = random.uniform(5, 20)
  
      # &quot;Remove&quot; the sprite when it &quot;passes the 'left edge' of the screen.&quot;
      def update(self):
          # Check and make sure that the &quot;right side&quot; of the rectangle has &quot;gone past&quot; the &quot;left side&quot; of
          # the screen at the &quot;pre-defined 'speed:'&quot;
          self.rect.move_ip(-self.speed, 0)
  
          # If the &quot;right side&quot; of the rectangle has &quot;gone past&quot; the &quot;left side&quot; of the screen at the
          # &quot;pre-defined 'speed,' then &quot;'prevent it' from being 'processed' any further by 'killing it:'&quot;
          if self.rect.right &lt; 0:
              self.kill()
  
  
  # &quot;'Create' the 'new and 'following' 'surfaced 'text'' 'with' the 'pre-defined' 'style'' and 'center' it
  # on the 'screen:'&quot;
  class TheStartButtonDisplay(pygame.sprite.Sprite):
  
      def __init__(self):
          super(TheStartButtonDisplay, self).__init__()
  
          # &quot;Define&quot; the new &quot;text's 'font:'&quot;
          self.the_start_button_font = pygame.font.Font(&quot;8-BIT WONDER.ttf&quot;, 36)
  
          # &quot;'Create' the 'new and 'following' 'surfaced 'text:''&quot;
          self.the_start_button_surface = self.the_start_button_font.render('Start', True, &quot;Black&quot;)
  
          # &quot;'Center' the 'new and 'following' 'surfaced 'text:''&quot;
          self.the_start_button_surface_rect = self.the_start_button_surface.get_rect(center=(400, 300))
  
  
          # &quot;'Establish' a '''singular' limit' condition' for the 'amount of times' a 'player' can 'click'
          # the ''start' button display:'&quot;
          self.the_mouse_click_limiter = False
  
      def is_being_displayed(self):
  
          # &quot;'Display' the 'new and 'following' 'surfaced 'text:''&quot;
          Screen.blit(self.the_start_button_surface, self.the_start_button_surface_rect)
  
  
      def is_being_clicked(self):
  
          the_players_action = False
  
          # &quot;'Get' the ''player's' 'mouse 'position:'''&quot;
          the_mouse_position = pygame.mouse.get_pos()
  
          # &quot;'Check' to 'see' 'when the 'player' ''moves' their mouse 'over' 'and or' then 'clicks' the ''start'
          # button display:''&quot;
          # &quot;'Check' to 'see' 'when the 'mouse cursor' 'collides' 'with' the the ''start' button display:''&quot;
          if self.the_start_button_surface_rect.collidepoint(the_mouse_position):
  
              # &quot;'Check' to 'see' 'when the ''start' button display' has been 'left-clicked' by the 'player'
              # 'only 'once:'''&quot;
              if pygame.mouse.get_pressed()[0] == 1 and self.the_mouse_click_limiter is False:
                  the_players_action = True
                  self.the_mouse_click_limiter = True
  
          # &quot;'Check' to 'see' 'when the ''start' button display'' has been 'released' ''after' 'being
          # 'left-clicked' 'only once:''' by the 'player:'&quot;
          if pygame.mouse.get_pressed()[0] == 0:
              # &quot;'if' the 'player' 'releases' their 'mouse's ''left' button,'' 'then '''reset'
              # 'the_mouse_click_limiter'' 'back' to 'False:'''&quot;
              self.the_mouse_click_limiter = False
  
          # &quot;'Update' the ''player's' 'action'' ''when' they ''click' the ''start' button display:'''&quot;
          return the_players_action
  
  
  # |---------------------------------------------------------------------------------------------------------|
  # |                     | &quot;INITIALIZE&quot; the program and &quot;CREATE&quot; Its &quot;DISPLAY WINDOW!&quot; |                     |
  # |---------------------------------------------------------------------------------------------------------|
  
  # Initialize PyGame:
  pygame.init()
  
  # &quot;'Define' and then 'create' a 'new 'display window'' ''with' the 'given 'perimeters:'''&quot;
  Screen = pygame.display.set_mode(size=(800, 600))
  
  # |---------------------------------------------------------------------------------------------------------|
  # |                     | &quot;LOAD&quot; and Then &quot;SCALE&quot; the Program's &quot;BACKGROUND SURFACE!&quot; |                     |
  # |---------------------------------------------------------------------------------------------------------|
  
  # &quot;'Create' a 'new ''imaged' surface:''&quot;
  The_Background_Surface = pygame.image.load(&quot;Troposphere_Bg.png&quot;).convert_alpha()
  
  # &quot;'Scale' the 'new ''imaged' surface'' 'to' the 'given 'perimeters:''&quot;
  The_Background_Surface = pygame.transform.scale(The_Background_Surface, size=(800, 600))
  
  # |---------------------------------------------------------------------------------------------------------|
  # |           | These Two Lines of Codes &quot;'CREATES' 'CUSTOM 'UNIQUE' EVENTS'&quot; &quot;IN&quot; The Program! |           |
  # |---------------------------------------------------------------------------------------------------------|
  
  # &quot;'Create' a 'new 'custom 'unique' event (By adding '1' to the 'USEREVENT')''' for 'adding' 'new 'enemies,''
  # that will later then get 'included' into 'the_group_of_sprites' on 'line: '370:''&quot;
  Add_New_Enemies = pygame.USEREVENT + 1
  
  # &quot;''Insert' 'this event' ''into' the 'event queue'' at 'regular intervals' ''throughout' the game' by 'firing'
  # ''new' 'enemies'' 'every '250 milli-seconds,' or 'four times per second'' 'towards the ''left side' of the
  # 'screen:'''&quot;
  pygame.time.set_timer(Add_New_Enemies, 250)
  
  # |---------------------------------------------------------------------------------------------------------------------|
  # |   | These Lines of Codes Will'  GROUPS'&quot; The &quot;PROGRAM'S 'ELEMENTS'&quot; &quot;AFTER&quot; It &quot;'INSTANTIATES' A 'NEW 'PLAYER!'&quot; |   |
  # |---------------------------------------------------------------------------------------------------------------------|
  
  # &quot;'Instantiate' a 'new 'player.''&quot;
  
  Player = Player()
  
  # &quot;''Create' 'groups'' to ''hold' ''every' sprite' in the program:'&quot;
  
  # &quot;'The_Enemies' 'will be 'grouped' and 'used for 'collision detection' and 'position updates.'''&quot;
  The_Enemies = pygame.sprite.Group()
  
  # - &quot;''All' of the 'sprites'' 'will be 'grouped' and 'used for 'rendering.'''&quot;
  the_group_of_sprites = pygame.sprite.Group()
  
  # - &quot;'Add' the 'player' to the ''group' of 'sprites:''&quot;
  the_group_of_sprites.add(Player)
  
  # |---------------------------------------------------------------------------------------------------------|
  # |      | These Three Lines of Codes &quot;'CREATES' 'INSTANCES!'&quot; For the Program's &quot;'TEXTS' DISPLAYS!&quot; |      |
  # |---------------------------------------------------------------------------------------------------------|
  
  # &quot;'Create' a 'new 'instance'' for the ''start' button' using the ''TheStartButtonDisplay' class:'&quot;
  the_start_button = TheStartButtonDisplay()
  
  # |---------------------------------------------------------------------------------------------------------|
  # |                                     | The Program's &quot;VARIABLES!!&quot; |                                     |
  # |---------------------------------------------------------------------------------------------------------|
  
  # &quot;'Run' this program 'until' the 'player' 'decides to 'quit:''&quot;
  Running = True
  
  # # &quot;This very important line of code will 'act' as a 'boolean operator' to 'satisfy ''specific' conditions'
  # for 'certain 'executions'' ''of' and 'throughout'' the program:'&quot;
  the_games_running_status = False
  
  # &quot;'Set' the 'background 'surface position'' 'to the 'pre-defined 'value:'''&quot;
  The_Background_Surface_Position = 0
  
  
  # |---------------------------------------------------------------------------------------------------------|
  # |                          | This Is Our Program's &quot;MAIN 'CONDITIONAL' LOOP!'&quot; |                          |
  # |---------------------------------------------------------------------------------------------------------|
  
  # &quot;'Give' the 'player' the ''option' to 'adjust'' the 'frame rate' of the program:&quot;
  The_Frame_Rate = pygame.time.Clock()
  
  
  # This is the &quot;main 'conditional' loop:&quot;
  class TheMainConditionalLoop(pygame.sprite.Sprite):
      while Running:
  
          # |----------------------------------------------------------------------------------------------------------|
          # |            | These Seven &quot;IMPORTANT&quot; Lines of Codes &quot;ANIMATED&quot; the Program's &quot;BACKGROUND!!&quot; |            |
          # |----------------------------------------------------------------------------------------------------------|
  
          # &quot;'Fill' the ''initial' 'Surface'' of the 'screen' 'white:'&quot;
          Screen.fill(&quot;White&quot;)
  
          # &quot;'Draw' the 'background 'Surface (Or 'image,' i.e., 'Troposphere_Bg.png')'' ''on' the 'screen' 'at'
          # the 'given position:''&quot;
          Screen.blit(The_Background_Surface, (The_Background_Surface_Position, 0))
  
          # &quot;'Draw' 'another 'background 'Surface (Or 'image,' i.e., 'Troposphere_Bg.png')'' ''on' the 'screen'
          # 'at' the 'given position:''&quot;
          Screen.blit(The_Background_Surface, (The_Background_Surface_Position + 800, 0))
  
          # &quot;'After' the 'background 'Surface (Or 'image,' i.e., 'Troposphere_Bg.png')'' 'moves 'beyond' the 'width'
          # of the 'screen,'' ''reset' its 'position'' and 'continue 'looping' it' at the 'program's ''pre-defined'
          # 'speed:'''&quot;
          if The_Background_Surface_Position &lt;= -800:
              Screen.blit(The_Background_Surface, (The_Background_Surface_Position + 800, 0))
              The_Background_Surface_Position = 0
          The_Background_Surface_Position -= 20
  
          # |----------------------------------------------------------------------------------------------------------|
          # |                                                                                                          |
          # |----------------------------------------------------------------------------------------------------------|
  
          # &quot;''look' at' ''every' event' ''in' the 'queue:''&quot;
          for the_event in pygame.event.get():
  
              # &quot;'Only' ''run' the program 'after' the 'player' has 'clicked' the ''start' button display (OR--see the
              # codes below between 'line: '306-310''):''&quot;
              if the_start_button.is_being_clicked():
                  the_games_running_status = True
  
              # &quot;'Check' to 'see' 'when the ''post-defined' keyboard buttons (I.e., 'K_ESCAPE,' and 'K_RETURN') are
              # ''pressed' and 'released'' 'as 'events''' in the queue:&quot;
              if the_event.type == KEYDOWN:
  
                  # &quot;'Only' ''run' the program 'after' the 'player' has 'pressed' the ''return (Or 'enter')' key' on
                  # their keyboard (OR--see the codes above between 'line: '297-302''):'&quot;
  
                  if the_event.key == K_RETURN:
                      the_games_running_status = True
  
                  # Did the &quot;player&quot; &quot;hit&quot; the &quot;'Escape (ESC)' key?&quot; &quot;If so,&quot; then &quot;'terminate' the 'program' by
                  # ''setting' 'Running' to 'False:''&quot;
                  if the_event.key == K_ESCAPE:
                      Running = False
  
              # Did the &quot;player&quot; &quot;click&quot; the &quot;Window 'exit' button?&quot; &quot;If so,&quot; then &quot;'terminate' the 'program' by
              # ''setting' 'Running' to 'False:''&quot;
              elif the_event.type == QUIT:
                  Running = False
  
              # &quot;'Add' 'new 'enemies'' ''every' frame' '''throughout' the program' 'until the 'player' 'exits' it:''&quot;
              elif the_event.type == Add_New_Enemies:
  
                  if the_games_running_status is True:
  
                      # &quot;'Create' the 'new 'enemy'' and ''add' it' to 'sprite groups:'&quot;
                      The_New_Enemy = Enemy()
  
                      # - &quot;'Add' 'The_New_Enemy' to the ''group' of 'The_Enemies:''&quot;
                      The_Enemies.add(The_New_Enemy)
  
                      # - &quot;'Add' 'The_New_Enemy' to 'the_group_of_sprites:'&quot;
                      the_group_of_sprites.add(The_New_Enemy)
                  else:
                      the_games_running_status = False
  
          # |----------------------------------------------------------------------------------------------------------|
          # |                       | These Three Lines of Codes Are for the &quot;USER'S INPUTS!!&quot; |                       |
          # |----------------------------------------------------------------------------------------------------------|
  
          # &quot;'Return' ''all' of the 'keys'' that were ''pressed' 'by' the 'player'' and 'then ''stored' 'in 'queue'''
          # 'by' the 'program:''&quot;
          Pressed_Keys = pygame.key.get_pressed()
  
          # &quot;'Update' the '''player's' 'player 'sprite 'position''' ''every frame' ''based upon' the ''keys' 'that were
          # 'pressed' ''by' the 'player''''''' on their keyboard:&quot;
          Player.update(Pressed_Keys)
  
          # &quot;'Update' the ''enemies' sprites' 'positions:'&quot;
          The_Enemies.update()
  
          # |----------------------------------------------------------------------------------------------------------|
          # |                                   | &quot;DISPLAY&quot; the Program's &quot;TEXTS!&quot; |                                   |
          # |----------------------------------------------------------------------------------------------------------|
  
          if the_games_running_status:
              the_start_button.is_being_displayed()
  
          # |---------------------------------------------------------------------------------------------------------|
          # |  | These Four Lines of Codes&quot;  'DETECTS' ANY 'COLLISION' 'BETWEEN' THE 'PLAYER' AND 'ENEMY' CLASSES!! |  |
          # |---------------------------------------------------------------------------------------------------------|
  
          # &quot;''Draw' 'all'' 'sprites' to the 'screen:'&quot;
          for all_of_the_sprites in the_group_of_sprites:
              Screen.blit(all_of_the_sprites.The_Surface, all_of_the_sprites.rect)
  
          # &quot;'Check' to 'see' ''whether' or 'not'' the 'player' 'has ''collided' ''with' 'any'' ''enemy' sprite'''&quot;
          if pygame.sprite.spritecollideany(Player, The_Enemies):
              the_games_running_status = False
  
          # |----------------------------------------------------------------------------------------------------------|
          # |                                                                                                          |
          # |----------------------------------------------------------------------------------------------------------|
  
          # Calling &quot;flip()&quot; after &quot;blit(image (left, top))&quot; will update the &quot;display&quot; with the newly drawn
          # &quot;Surface&quot; or else nothing will change. &quot;'blit()' 'draws the 'image' 'to the 'screen' at the ''given'
          # position.''&quot; It accepts either a &quot;Surface&quot; or a &quot;string&quot; as its &quot;image parameter.&quot; If image is a
          # &quot;str&quot; then the named image will be &quot;loaded from the 'images'/directory.&quot;
          pygame.display.flip()
  
          # &quot;Ensure&quot; that the program &quot;maintains&quot; a &quot;frame rate&quot; of &quot;x&quot; &quot;frames per second:&quot;
          The_Frame_Rate.tick(30)
  </code></pre>