Im trying to wrte a simple word pad like app using pygame but cant seem to get the text to go to a new line after its too long for the screen. Heres the code:

import pygame
from pygame.locals import*
pygame.init()

def newline(font,screen,line):
txt_l = font.size(line)
if txt_l > screen :

x = 0
y = 50
else:
x = 0
y = 0
return y

def main():


size = 600,200
screen = pygame.display.set_mode(size)

font = pygame.font.Font(None,30)

pic = pygame.image.load('bad.jpg').convert()
picrect = pic.get_rect()

screen.blit(pic, picrect)
pygame.display.flip()

text =''
oldtext = ''
i = 0
x = 0
y = newline(font, 600, text)

while 1:

i = i + 1

for event in pygame.event.get():
if event.type == QUIT:
return

elif event.type == KEYDOWN:


newtext = str(event.unicode)
text = oldtext + newtext
text2 = str(font.size(text))
ren = font.render(text,0,(250,250,250))
ren2 = font.render(text2,0,(250,250,250))


screen.blit(pic, picrect)
screen.blit(ren,(x,y))
screen.blit(ren2,(20,20))
pygame.display.flip()

oldtext = text


if __name__=='__main__': main()

eveytime it gets to the point that the text is off the screen it says that the area that i'm trying to blit to is invalid. please help if you can, it will be greatly appreciated