Dec-15-2020, 04:42 PM
(This post was last modified: Dec-15-2020, 04:43 PM by djwilson0495.)
Sorry I copied my previous code over. The code is currently:
import pygame from pygame.locals import * import time class Print: """Draw text to the screen.""" # text is editable with the keyboard # options for font and background colour BLACK = (0, 0, 0) RED = (255, 0, 0) GREEN = (0, 255, 0) BLUE = (0, 0, 255) GRAY = (200, 200, 200) pygame.init() screen = pygame.display.set_mode((640, 240)) # creates a screen 640 x 240 pixels in size sysfont = pygame.font.get_default_font() print('system font :', sysfont) text = 'This text is editable' font = pygame.font.SysFont(None, 24) img = font.render(text, True, RED) rect = img.get_rect() running = True background = GRAY while running: for game_event in pygame.event.get(): if game_event.type == QUIT: running = False if game_event.type == KEYDOWN: if game_event.key == K_BACKSPACE: if len(text)>0: # if length of text is > 0 text = text[:-1] # delete the last letter in the string else: text += game_event.unicode # else add the letter to the end of the string img = font.render(text, True, RED) rect.size=img.get_size() cursor.topleft = rect.topright screen.fill(background) screen.blit(img, (20, 20)) pygame.display.update() pygame.quit()This matches up with the error in my previous post