def keyfunc( key, x, y): # escape or q or Q if (key == 27 or key == 'q' or key =='Q'): exit(0)