I'm trying to create a little text module for pygame. I've got everything up and running but I can't seem to get list.pop() to work. Whenever a person presses a key I put the chr() version of it into a list, then I iterate over that list to print out the word (not the best way, I know, I'm working on it though). Now, whenever I try to put in a backspace nothing happens.
When I try it now it just puts a space into the text. Any help would be great!
Here's part of my code:
def ptext(x, y, text, size=30, color=(255,255,255)):
font = pygame.font.Font("secrcode.ttf", size)
img_text = font.render(text, True, color)
screen = pygame.display.get_surface()
screen.blit(img_text, (x,y))
def main():
#different windows
main_menu = False
text_box = True
check_text = False
pygame.init()
screen = pygame.display.set_mode((500,500))
pygame.display.set_caption("Pygame Text-box Prototype")
font = pygame.font.Font("secrcode.ttf", 30)
#create the text box
text = Text_Box(screen)
word = []
while True:
for event in pygame.event.get():
if event.type == QUIT:
sys.exit()
if event.type == KEYDOWN:
if event.type == K_BACKSPACE:
word.pop()
if event.type == K_SPACE:
word.append(" ")
else:
word.append(chr(event.key))
keys = pygame.key.get_pressed()
if keys[K_ESCAPE]:
sys.exit()
start = 90
try:
for i in word:
ptext(start, 260, i)
start += 17
except:
ptext(70, 250, "?")
ptext(10, 10, "Text Box")
text.draw_text_box()
pygame.display.update()
main()