I'm creating a typing game, and I'm trying to display a random line of text from a .txt file, the only problem, when it shows up on the pygame window, it has this at the end: []. Any suggestions? Any questions on other code that isn't showed can be answered. I didn't want to post the entire thing, it's a huge mess. The words in the text file are on their own line. Here is the code that is being used:
import random
import pygame
gameDisplay = pygame.display.set_mode((display_width, display_height))
vSmallFont = pygame.font.SysFont("Comicsansms", 10)
smallFont = pygame.font.SysFont("Comicsansms", 20)
medFont = pygame.font.SysFont("Comicsansms", 45)
largeFont = pygame.font.SysFont("Comicsansms", 55)
def text_objects(text, color, size):
if size == "small":
textSurf = smallFont.render(text, True, color)
elif size == "medium":
textSurf = medFont.render(text, True, color)
elif size == "large":
textSurf = largeFont.render(text, True, color)
elif size == "verySmall":
textSurf = vSmallFont.render(text, True, color)
return textSurf, textSurf.get_rect()
def messageToScreen(msg, color, y_displace = 0, size = "small"):
textSurface, textRect = text_objects(msg, color, size)
textRect.center = (display_width/2), (display_height/2) + y_displace
gameDisplay.blit(textSurface, textRect)
#This function is later called
def randWord():
rand = random.randint(0,1000)
fp = open("1.txt")
for i, line in enumerate(fp):
if i == rand:
messageToScreen(line,black,-200,size = "large")
fp.close()