You could also use EzText. It is a module that basically does what FRJA describes for you. There are plenty of other modules if you google "pygame text input." Here is EzText's example code:
# EzText example
from pygame.locals import *
import pygame, sys, eztext
def main():
# initialize pygame
pygame.init()
# create the screen
screen = pygame.display.set_mode((640,240))
# fill the screen w/ white
screen.fill((255,255,255))
# here is the magic: making the text input
# create an input with a max length of 45,
# and a red color and a prompt saying 'type here: '
txtbx = eztext.Input(maxlength=45, color=(255,0,0), prompt='type here: ')
# create the pygame clock
clock = pygame.time.Clock()
# main loop!
while 1:
# make sure the program is running at 30 fps
clock.tick(30)
# events for txtbx
events = pygame.event.get()
# process other events
for event in events:
# close it x button si pressed
if event.type == QUIT: return
# clear the screen
screen.fill((255,255,255))
# update txtbx
txtbx.update(events)
# blit txtbx on the sceen
txtbx.draw(screen)
# refresh the display
pygame.display.flip()
if __name__ == '__main__': main()