display text in pygame

import pygame
pygame.init()
window = pygame.display.set_mode((500, 500)) 

def set_text(string, coordx, coordy, fontSize): #Function to set text

    font = pygame.font.Font('freesansbold.ttf', fontSize) 
    #(0, 0, 0) is black, to make black text
    text = font.render(string, True, (0, 0, 0)) 
    textRect = text.get_rect()
    textRect.center = (coordx, coordy) 
    return (text, textRect)

window.fill((255, 255, 255)) #Fills the whole window with white
#Places "Text in Pygame!" with an x,y coord of 250, 250 and 60 font size
totalText = set_text("Text in Pygame!", 250, 250, 60)
window.blit(totalText[0], totalText[1])
pygame.display.update()

4.25
4
Lionel Aguero 33605 points

                                    def writeText(string, coordx, coordy, fontSize):
  	#set the font to write with
    font = pygame.font.Font('freesansbold.ttf', fontSize) 
    #(0, 0, 0) is black, to make black text
    text = font.render(string, True, (0, 0, 0))
    #get the rect of the text
    textRect = text.get_rect()
    #set the position of the text
    textRect.center = (coordx, coordy)
    #add text to window
	window.blit(text, textRect)
    #update window
	pygame.display.update()

4.25 (4 Votes)
0
4.67
3
A-312 69370 points

                                    """system font"""
font = pygame.font.SysFont("Segoe UI", 35)

"""font from .ttf file"""
font = pygame.font.Font("path/to/font.ttf", 35)

textsurface = font.render("text", False, color)  # "text", antialias, color
surface.blit(textsurface, (x, y))

4.67 (3 Votes)
0
3
2
Awgiedawgie 440220 points

                                    font = pygame.font.SysFont(None, 24)
img = font.render('hello', True, BLUE)
screen.blit(img, (20, 20))

3 (2 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
text box pygame how to create text in pygame font text in pygame how to use custom fonts in pygame pygame use custom font write words on pygame show text in pygame using font in pygame write word in pygame pygame add a custom font pygame custome font pygame use a custom font how to add text pygame how to place text pygame how to add font in pygame font.Font() pygame how to do formatting in pygame text add text in pygame what is font in pygame how to create custom font pygame how to create font pygame how to load a font in pygame built in fonts in pygame add text to window pygame how to add fonts to pygame pygame.font.Font(' can you make text boxes in pygame pygame display text box how to display text using pygame how to display simple text with pygame how to type text on pygame write text in pygame how to set font by file in pygame how to put text pygame custom fonts pygame how to show text in pygame display text alongside pygame pygame [add text] add text site:pygame.org how to make a texting app with pygame making a texting app with pygame how to load font in pygame pygame text display how to add text to pygame window pygame make text displaying pygame how to set font how to add text to pygame font style in pygame font to use for pygame pygame font.font basic text in pygame How toadd text to pygame python pygame font how towrite a text in pygame how to put text on screen pygame HOW TO PRINT text with pygame how to make a text with pygame pygame adding text pygame ttf font how to add a font to pygame how to add a text to pygame how to position text in pygame python pygame fonts pygame add text writing text in pygame how to render font in pygame pygame set font how to render text in pygame how to diplay text in pygame pygame libale use fonts how to write in text pygame render text in pygame text on pygame writing text pygame pygame how to put text on screen pygame font all examples pygame font all example pygame font example pygame text with class pygame writing txt writing text on pygame how to display font in pygame show text pygame hw to put text in pygame how to draw a font in pygame pygame.font.Font how to make custom font pygame how to display text pygame how to display text with pygame how to draw text pygame how to draw text in pygame .text pygame pygame text mehtod how to change font pygame pygame text basics how to render the default font in pygame different fonts in pygame how to write a text in pygame print text in pygame how to use text in pygame how to put text on a pygame window how to make text pygame custom font pygame add text to pygame pygame Sysfont and font write some text pygame pygame create text pygame custom font different font in pygame pygame built in fonts draw text pygame rendering text in pygame how to put text in pygame using custom fonts in pygame .ttf using custom fonts in pygame How to download a font in pygame how to add text in pygame window add text in pygame window adding text in pygame pygame set text pygame text render pygame displaying text displaying text in pygame how to draw text with pygame Font class python pygame how to print text in pygame text in pygame how do I use a ttf font in pygame how do I use a font in pygame how to import a font for pygame what font does pygame use python pygame add text how to put text on pygame window python pygame display text fonts for pygame font object in pygame pygame rect with text how to make text in pygame how to make a text box in pygame text onto pygame screen how to display text in pygame pygame write text text in pygame how to use a trutype font file in pygame pygame type of text display text in pygame how to write in pygame write tesxt pygame how to render somthing in pygame pygame write text to screen 'enter' missed while rendering text in pygame how to add text on screen pygame pygame render font render pygame write text with pygame pygame text to surfuce pygame text pygame show text pygame print to display pygame display text in game window display text with pygame pygame draw text to screen make text in pygame blitting text in pygame pygame show text on screen how to get text on pygame text in pyagme pygame add text to surface diplay text pygame display text pygame how to write texct pygame how to display a message in pygame how to blit text in pygame pygame fonts list pygame.font.init how to write text in a pygame window draw text in pygame sysfont pygame paste a text inside pygame pygame font size how to make letters bold pygame pygame.font.Font(None, 20) text in pyygame output a message on pygame font.get_height pygame python pygame font.render how to make a textbox in pygame text_object pygame pygame drawin text resizd draw text in pygame python how to add text to a box pygame render text over rectangle pygame display big text on screen in python font render python pygame box with text render in pygame fonts pygame font types in pygame font render pygame sysfont pygame how to display text font1 = pygame.font.SysFont(None, 32)#normal font with size of 32;font design not specified.text1=font1.render("H what are the three arguments of font . render in pygame font pygame font list pygame print text on screen pygame print text pygame insert text in pygame example of text box in pygame how to place a text in pygame font supported by pygame pygame font.render definition pygame font text on screen for longer pygame how to get a text surface how to add text in pygame how to add text on python window using pygame sysfont render pygame font = pygame.font.Font('freesansbold.ttf', 32) add text using pygame pygame fonts pygame write in text to screen pygame Desping text how to change the size of font pygame how to use text on pygame pygame function to display a message smallfont.render in pygame meaning smallfont.render get a list of system fonts for pygame drawing text on a surface pygame python pygame text pygame font.text mit background pygame overlay-text mit hintergrund pygame text fonts render pygame python pygame text in GUI pygame.text pygame display text pygame print text printing in pygame write in pygame pygame draw words render text pygame display text on the corner in pygame print to display pygame updating text in display create text in pygame how to render in pygame pygame add text to screen print in pygame pygame bigger text write on pygame window text in pyganme write words in pygame how to display something on a windown pygame font in pygame font.redner pygame how to write something on a pygame display message pygame sysfont arguments colr sysfont arguments can pygame print on the screen write text to screen pygame how to print a text in pygam e cool fonts for pygmae pygame.font.sysfont list pygame font.remder show text with pygame pygame render font kygame write text to screen text.get_width() pygame how to display text in a pygame window how to use fonts inj pygame how to initialize a font in pyhton pygame pygame.font pygame font return pygame font \n change font size again and again pygame what has font.render been replaced with in pygame pygame text message how to blit text pygame pygame text window types of fonts in pygame pygame text output What is true or false in font.render ppygame display text on a surface in pygame font.render how to show a text on pygame window all fonts in pygame fonts in pygame front.render pygame how to import a fonts in pygame how to import a new font in pygame how to import a font in pygame text pygame pygame write text on screen pygame. render text rendering pygame pygame draw text How to let text appear in pygame use print with pygae display print on pygame list of fonts with pygame rendering text pygam screen.draw.text pygame pygame font.render pygame blit text change text in font.render python how to display pygame display in python init font pygame how to write a font in pygame how to write letter on pygame change font size in python print pygame pygame fonts example pygame how to add text pygame font list pygame font pygame text on screen all pygame fonts Draw text over screen pygame pygame drawing text pygame writing tetx pygame font render pygame render text pygame bold font.render pygame how to put text on pygame pygame place text pygame.font.sysfont() write number pygame display text pygame without font object pygame blit text example text used in pygame display string pygame how to align a window on the screen in python pygame how to write text in pygame python how to write text in pygame
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source