I see a couple of small errors in your code but I am not sure wether this is the cause of the segfault, try this:
from contextlib import closing
if hero.colliderect(finishline):
starttimer = running = 0
with closing(shelve.open('highscores.txt')) as d:
highscore = d['highscore']
if time < highscore:
d['highscore'] = time
player = easygui.enterbox(msg=("Congratulations you have set a new highscore of {0}. Please enter your name: ".format(time)))
d['player'] = player
else:
player = d['player']
easygui.msgbox(msg=("Congratulations you have finished with a time of {0}. The highscore is {1} set by {2}".format(time, highscore, player)))