python - how can I add text to these rectangles? -


this code have started use make start menu.

# need colours!! black = (0,0,0) white = (255,255,200) red = (200,0,0) green = (0, 200, 0) bright_red = (255, 0 ,0) bright_green = (0, 255, 0) bright_white = (255, 255, 255)  def main():     pygame.init()      screen = pygame.display.set_mode((600, 600))      pygame.display.set_caption("crazypongmainmenu")      menu = cmenu(50, 50, 20, 5, "vertical", 100, screen,                    [("start game", 1, none),                     ("options",    2, none),                     ("exit",       3, none)])      menu.set_center(true, true)      menu.set_alignment("center", "center")      state = 0     prev_state = 1      rect_list = []      pygame.event.set_blocked(pygame.mousemotion)      while 1:       if prev_state != state:          pygame.event.post(pygame.event.event(event_change_state, key = 0))          prev_state = state       e = pygame.event.wait()        if e.type == pygame.keydown or e.type == event_change_state:          if state == 0:             rect_list, state = menu.update(e, state)          elif state == 1:             print ("start game!")             state = 0          elif state == 2:             print ("options!")             state = 0          else:             print ("exit!")             pygame.quit()             sys.exit()        if e.type == pygame.quit:          pygame.quit()          sys.exit()        mouse = pygame.mouse.get_pos()        #print(mouse)        if 200+150 > mouse[0] > 200 , 250+30 > mouse[1] > 250:           pygame.draw.rect(screen, bright_green,(200, 250, 150, 30))       else:           pygame.draw.rect(screen, green,(200, 250, 150, 30))        if 200+150 > mouse[0] > 200 , 290+21 > mouse[1] > 290:           pygame.draw.rect(screen, bright_white,(200, 290, 150, 21))       else:           pygame.draw.rect(screen, white,(200, 290, 150, 21))        if 200+150 > mouse[0] > 200 , 318+25 > mouse[1] > 318:           pygame.draw.rect(screen, bright_red,(200, 318, 150, 25))       else:           pygame.draw.rect(screen, red,(200, 318, 150, 25))        pygame.display.update(rect_list)  if __name__ == ("__main__"):    main() 

i put text onto 3 rectangles don't know how to. if please tell how put text onto rectangles appreciated!

check out stack overflow question: how add text pygame rectangle

specifically these bits:

self.font = pygame.font.sysfont('arial', 25)  def addtext(self):     self.screen.blit(self.font.render('hello!', true, (255,0,0)), (200, 100))     pygame.display.update() 

basically want define font

then blit onto screen, render takes args (text, antialias (you want true), color)

and update


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -