Python pygame 模块,QUIT 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用pygame.QUIT

项目:SmartCar    作者:amarlearning    | 项目源码 | 文件源码
def Kaboom(score):
    init()
    gameDisplay.blit(GameOver,(382,175))
    pygame.draw.rect(gameDisplay, white, (200, 400, 550, 50))
    text = smallfont.render("Press [RETURN] to continue and [Q] to quit", True, darkBlue)
    gameDisplay.blit(text, [370,400])
    text = smallfont.render("Score : " + str(score), True, red)
    gameDisplay.blit(text, [450,420])
    pygame.display.update()
    gameExit = True
    while gameExit:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_RETURN:
                    gameExit = False
                    gameloop()
                if event.key == pygame.K_q:
                    pygame.quit()
项目:ToeBot    作者:barkdong123    | 项目源码 | 文件源码
def turn(self):
        global board,whos_turn,n_of_turn

        for event in pygame.event.get():
            if (event.type == pygame.MOUSEBUTTONDOWN):
                mouse_pos = pygame.mouse.get_pos()
                for i in range(3):
                    for j in range(3):
                        if (sqr_pos[i][j][0] < mouse_pos[0] and sqr_pos[i][j][0] + sqr_size[0] > mouse_pos[0] and
                                    sqr_pos[i][j][1] < mouse_pos[1] and sqr_pos[i][j][1] + sqr_size[1] > mouse_pos[
                            1] and board[i*3+j] == NO_ONE):

                            board[i*3+j] = whos_turn
                            n_of_turn += 1
                            who_won(tuple(board) ,whos_turn, n_of_turn)
                            reward_consider(winner,tuple(board),p1,p2)
                            whos_turn = self.ID ^ 1


            elif (event.type == pygame.K_ESCAPE):
                esc_pause()

            if (event.type == pygame.QUIT):
                sys.exit()
                # -------------------------------------------
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def main():
    pygame.init()
    screen = pygame.display.set_mode((500,500))
    screen.fill((255, 0, 0))
    s = pygame.Surface(screen.get_size(), pygame.SRCALPHA, 32)
    pygame.draw.line(s, (0,0,0), (250, 250), (250+200,250))

    width = 1
    for a_radius in range(width):
        radius = 200
        pygame.gfxdraw.aacircle(s, 250, 250, radius-a_radius, (0, 0, 0))

    screen.blit(s, (0, 0))
    pygame.display.flip()
    try:
        while 1:
            event = pygame.event.wait()
            if event.type == pygame.QUIT:
                break
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE or event.unicode == 'q':
                    break
            pygame.display.flip()
    finally:
        pygame.quit()
项目:opseilen    作者:Baal221    | 项目源码 | 文件源码
def program_loop(self):
        while not process_ev.process_events():
            self.update()
            self.draw()

# Handeling pygame events
#def process_events():
#   for event in pygame.event.get():
#       if event.type == pygame.QUIT:
#           return True
#       #elif event.type == pygame.KEYDOWN:
#       #   game.Player1.key_event(event)
#   return False
项目:cs6244_motionplanning    作者:chenmin1107    | 项目源码 | 文件源码
def keyboard_loop(self):
        while not rospy.is_shutdown():
            acc = 0
            yaw = 0

            keys = pygame.key.get_pressed()
            for event in pygame.event.get():
                if event.type==pygame.QUIT:
                    sys.exit()

            if(keys[pygame.K_UP]):
                acc = self.acc
            elif(keys[pygame.K_DOWN]):
                acc = -self.acc
            if(keys[pygame.K_LEFT]):
                yaw = self.yaw
            elif(keys[pygame.K_RIGHT]):
                yaw = -self.yaw

            self.send_control(acc, yaw)
            self.rate.sleep()
项目:project_xcape    作者:OthmanEmpire    | 项目源码 | 文件源码
def handleEvent(self, _):
        for event in pg.event.get():

            if event.type == pg.QUIT:
                sys.exit()
            if event.type == pg.KEYDOWN:
                if event.key == pg.K_F4:
                    sys.exit()

            if (event.type == self.MENU_EVENT
                    or event.type == pg.KEYDOWN):
                self.menuEngine.handleEvent(event)

            if (event.type == self.SCENE_EVENT
                    or event.type == pg.KEYDOWN
                    or event.type == pg.KEYUP):
                self.sceneEngine.handleEvent(event)

            if (event.type == self.CUTSCENE_EVENT
                    or event.type == pg.KEYDOWN):
                self.cutsceneEngine.handleEvent(event)
项目:Tutoriales_juegos_Python    作者:tidus747    | 项目源码 | 文件源码
def handle_event(self, event):
        if event.type == pygame.QUIT:
            game_over = True

        if event.type == pygame.KEYDOWN:

            if event.key == pygame.K_LEFT:
                self.update('left')
            if event.key == pygame.K_RIGHT:
                self.update('right')
            if event.key == pygame.K_UP:
                self.update('up')
            if event.key == pygame.K_DOWN:
                self.update('down')

        if event.type == pygame.KEYUP:

            if event.key == pygame.K_LEFT:
                self.update('stand_left')
            if event.key == pygame.K_RIGHT:
                self.update('stand_right')
            if event.key == pygame.K_UP:
                self.update('stand_up')
            if event.key == pygame.K_DOWN:
                self.update('stand_down')
项目:Infinity-Game    作者:ISNSaintLaurent    | 项目源码 | 文件源码
def menu_info():
    rect_pointeur = pygame.Rect(pygame.mouse.get_pos(),(1,1))
    rect_retour = pygame.Rect((50,25), (180,35))
    for event in pygame.event.get():
        if event.type == pygame.QUIT :
            abientot()
            pygame.quit()
            quit()
        if event.type == pygame.MOUSEBUTTONDOWN:
            if rect_pointeur.colliderect(rect_retour):
                return 1

    fenetre.fill(blanc)
    fenetre.blit(calibri_font.render("< Retour", True, blue), (50, 30))
    fenetre.blit(InfoMenu, (0,80))

    if rect_pointeur.colliderect(rect_retour):
        fenetre.blit(calibri_font.render("< Retour", True, blue2), (50, 30))
    pygame.display.flip()

#Fonction lancée lorsque le joueur quitte et affichant un remerciement
项目:Physics-2.0    作者:rschwa6308    | 项目源码 | 文件源码
def handle_events(*args):
    settings_window, camera, scroll, done, dims, screen, bodies, G, COR = args
    for event in pg.event.get():
        if event.type == pg.VIDEORESIZE:
            width, height = event.w, event.h
            dims, screen = V2(width, height), pg.display.set_mode((width, height), pg.RESIZABLE)
        elif event.type == pg.KEYDOWN:
            scroll.key(event.key, 1)
            camera.key_down(event.key)
        elif event.type == pg.KEYUP:
            scroll.key(event.key, 0)
            camera.key_up(event.key)
        elif event.type == pg.MOUSEBUTTONDOWN:
            handle_mouse(settings_window, camera, event, bodies, dims, G, COR, scroll)
        done |= event.type == pg.QUIT
    return done, dims, screen
项目:asteroid-invasion    作者:mally1mk    | 项目源码 | 文件源码
def showscreen():   
    BG()
    draw_text(screen, "asteroid invasion", 50, WIDTH / 2, HEIGHT / 4)
    draw_text(screen, "left and right arrow to move", 20,WIDTH / 2, HEIGHT / 2-12.5)
    draw_text(screen, "press space to shoot", 20,WIDTH / 2, HEIGHT / 2-50)
    draw_text(screen, "if red bar turns green ", 20,WIDTH / 2, HEIGHT / 2+22)
    draw_text(screen, "press arrow up to use sonicshot", 20,WIDTH / 2, HEIGHT / 2+44)
    draw_text(screen,'highscore: '+str(highscore),18,WIDTH/2,400)
    draw_text(screen, "Press up arrow to start", 18, WIDTH / 2, HEIGHT * 3 / 4)
    pygame.display.flip()
    waiting = True
    while waiting:
        clock.tick(FPS)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                exit()
                pygame.exit()
            if event.type == pygame.KEYUP:
                if event.key == pygame.K_UP:
                    waiting = False
项目:spygame    作者:sven1977    | 项目源码 | 文件源码
def step(self, action):
        """
        (!)for reinforcement learning only(!) WIP:
        Executes one action on the game.
        The action gets translated into a keyboard sequence first, then is played.

        :param str action: the action to execute on the MDP
        """
        # default global events?
        events = pygame.event.get(pygame.QUIT)  # TODO: add more here?
        for e in events:
            if e.type == pygame.QUIT:
                raise (SystemExit, "QUIT")

        # collect keyboard events
        self.keyboard_inputs.tick()

        # call the callback with self (for references to important game parameters)
        self.callback(self)

        # increase global frame counter
        self.frame += 1
项目:universe    作者:openai    | 项目源码 | 文件源码
def _render(self):
        self.before_render()
        if not PYGAME_INSTALLED:
            return
        # For some reason pygame wants X and Y swapped
        aray, n = self.driver.flip()
        if self.screen is None:
            self.screen = pygame.display.set_mode(aray[0].shape[:2][::-1])
        surf = pygame.surfarray.make_surface(aray[0].swapaxes(0, 1))
        rect = surf.get_rect()
        self.screen.blit(surf, rect)
        pygame.display.flip()

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                self.close()
项目:Jeff-Long-Run    作者:matthiasrigaud    | 项目源码 | 文件源码
def manager(field):
    put_tile = False
    for event in pygame.event.get():
        if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.dict["key"] == pygame.K_ESCAPE):
            sys.exit()
        elif event.type == pygame.KEYDOWN and (event.dict["key"] == pygame.K_RIGHT or event.dict["key"] == pygame.K_d):
            field.change_right_move(True)
        elif event.type == pygame.KEYUP and (event.dict["key"] == pygame.K_RIGHT or event.dict["key"] == pygame.K_d):
            field.change_right_move(False)
        elif event.type == pygame.KEYDOWN and (event.dict["key"] == pygame.K_LEFT or event.dict["key"] == pygame.K_q):
            field.change_left_move(True)
        elif event.type == pygame.KEYUP and (event.dict["key"] == pygame.K_LEFT or event.dict["key"] == pygame.K_q):
            field.change_left_move(False)
        elif event.type == pygame.MOUSEBUTTONDOWN and event.dict["button"] == 4:
            field.change_tile(1)
        elif event.type == pygame.MOUSEBUTTONDOWN and event.dict["button"] == 5:
            field.change_tile(-1)
        elif event.type == pygame.MOUSEBUTTONDOWN and event.dict["button"] == 1:
            field.put_tile()
项目:Jeff-Long-Run    作者:matthiasrigaud    | 项目源码 | 文件源码
def manager(jeff, field, frame, level_select):
    for event in pygame.event.get():
        if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.dict["key"] == pygame.K_ESCAPE):
            sys.exit()
        elif event.type == pygame.KEYDOWN and jeff.is_dead() and event.dict["key"] == pygame.K_r:
            jeff = Jeff.Jeff([300, Constant.GROUND_HEIGHT - 50])
            field.reload_level()
        elif event.type == pygame.KEYDOWN and (jeff.is_dead() or field.is_level_ended()) and event.dict["key"] == pygame.K_m:
            jeff = Jeff.Jeff([300, Constant.GROUND_HEIGHT - 50])
            frame = "MENU"
        elif event.type == pygame.KEYDOWN and field.is_level_ended() and event.dict["key"] == pygame.K_n:
            next_level = level_select.get_next_level(field.get_level_file())
            if next_level != "":
                jeff = Jeff.Jeff([300, Constant.GROUND_HEIGHT - 50])
                field.load_level(next_level)
        elif event.type == pygame.KEYDOWN and event.dict["key"] == pygame.K_SPACE:
            jeff.jump(True)
        elif event.type == pygame.KEYUP and event.dict["key"] == pygame.K_SPACE:
            jeff.jump(False)
    return jeff, frame
项目:rpi_lcars    作者:tobykurien    | 项目源码 | 文件源码
def handleEvents(self):
        for event in pygame.event.get():
            if (event.type == pygame.QUIT) or \
                (event.type == KEYUP and event.key == K_ESCAPE):
                pygame.quit()
                self.running = False
                return

            for sprite in self.all_sprites.sprites():
                if hasattr(event, "pos"):
                    focussed = sprite.rect.collidepoint(event.pos)
                    if (focussed or sprite.focussed) and sprite.handleEvent(event, self.fpsClock):
                        break

            self.screen.handleEvents(event, self.fpsClock)

            newScreen = self.screen.getNextScreen()
            if (newScreen):
                self.all_sprites.empty()
                newScreen.setup(self.all_sprites)
                self.screen = newScreen
                break
项目:Circadia    作者:hooyah    | 项目源码 | 文件源码
def getEvent():
    """
    retrieve events from the clock, such as button clicks
    :return (tuple): (string(messageName), messageParam0, ...)
    """

    for event in pygame.event.get():
        if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
            return ('end', 0)
        elif event.type == pygame.KEYDOWN and event.key == 257:
            return ('buttonClick', 1)
        elif event.type == pygame.KEYDOWN and event.key == 258:
            return ('buttonClick', 2)
        elif event.type == pygame.KEYDOWN and event.key == 259:
            return ('buttonClick', 4)
        #elif event.type == pygame.KEYDOWN:
        #    print event.key

    return None
项目:pygame-flipclock    作者:prehensile    | 项目源码 | 文件源码
def update( self, dt, fps=8 ):

        self.display_time( dt.hour, dt.minute )    
        pygame.display.flip()

        # handle exits
        was_quit = False
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                was_quit = True
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    was_quit = True

        if not was_quit:
            self.clock.tick( fps )

        return was_quit
项目:pyDino    作者:lucaspbordignon    | 项目源码 | 文件源码
def show(self):
        # Setup
        self.display.set_screen_caption('Main Menu')
        last_mouse_click = (-1, -1)
        for event in pygame.event.get():
            if (event.type == pygame.QUIT):
                return (False, '', None)
            if (event.type == pygame.MOUSEBUTTONDOWN):
                last_mouse_click = pygame.mouse.get_pos()

        # New game button
        if (self.show_button(last_mouse_click, 'new_game')):
            return (True, 'choose_char', None)

        # Login button
        if (self.show_button(last_mouse_click, 'login')):
            return (True, 'login', None)

        # Logo
        self.display.display_single_image(self.buttons['pydino'][2],
                                          self.buttons['pydino'][0])

        # Default choice
        return (True, 'main_menu', None)
项目:pyDino    作者:lucaspbordignon    | 项目源码 | 文件源码
def show(self):
        """
        Shows the game over panel.
        """
        self.display.set_screen_caption('Game Over')
        for event in pygame.event.get():
            if (event.type == pygame.KEYDOWN):
                if (event.key == pygame.K_RETURN):
                    return (True, "main_menu", None)
                if (event.key == pygame.K_s):
                    return (True, "save_progress", None)
            if (event.type == pygame.QUIT):
                return (False, '', None)

        self.display.display_single_image(self.resources['game_over_msg'],
                                          self.resources['game_over_pos'])
        self.display.display_single_image(self.resources['game_over_char'],
                                          self.resources['game_over_pos'])
        self.display.display_single_image(self.resources['press_enter'],
                                          self.resources['press_enter_pos'])
        self.display.display_single_image(self.resources['save_msg'],
                                          self.resources['save_msg_pos'])
        return (True, 'game_over', None)
项目:Akkers2Beurs    作者:RensBoeser    | 项目源码 | 文件源码
def Loop(self): # game loop
        while not self.Exit:

            if self.Level == "menu": # loop only goes here if the level is 'menu'
                for event in pygame.event.get(): # checking for any events

                    if event.type == pygame.QUIT: # checks if someone tries to close the window
                        self.Exit = True # stops the while-loop
                    if event.type == pygame.KEYDOWN:
                        if event.key == pygame.K_ESCAPE:
                            self.Exit = True

                self.Draw() # black screen. draw all your things after this line

                grid.Draw()
                player1.Draw()
                player2.Draw()

                self.Tick() # refreshes the window. this is the end of the loop

            # you can use elifs here to make new levels

            else: self.Exit = True # if self.Level is not a valid level, it will terminate the while-loop

### FUNCTION DEFINITIONS ###
项目:Pygame_Functions    作者:StevePaget    | 项目源码 | 文件源码
def textBoxInput(textbox):
    # starts grabbing key inputs, putting into textbox until enter pressed
    global keydict
    textbox.text = ""
    while True:
        updateDisplay()
        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_RETURN:
                    textbox.clear()
                    return textbox.text
                elif event.key == pygame.K_ESCAPE:
                    pygame.quit()
                    sys.exit()
                else:
                    textbox.update(event)
            elif event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
项目:Pygame_Functions    作者:StevePaget    | 项目源码 | 文件源码
def textBoxInput(textbox):
    # starts grabbing key inputs, putting into textbox until enter pressed
    global keydict
    textbox.text = ""
    while True:
        updateDisplay()
        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_RETURN:
                    textbox.clear()
                    return textbox.text
                elif event.key == pygame.K_ESCAPE:
                    pygame.quit()
                    sys.exit()
                else:
                    textbox.update(event)
            elif event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
项目:backround-maker    作者:Fooliery887    | 项目源码 | 文件源码
def ask(self,question):
        word=""
        Text(self.game).draw_text2(self.default,question,green,wth//2,50) #example asking name
        pygame.display.flip()
        done = True
        while done:
            for event in pygame.event.get():
                if event.type==pygame.QUIT:
                    pygame.quit()
                    quit()
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_a:
                        word+=str(chr(event.key))
                    if event.key == pygame.K_b:
                        word+=chr(event.key)
                    if event.key == pygame.K_c:
                        word+=chr(event.key)
                    if event.key == pygame.K_d:
                        word+=chr(event.key)
                    if event.key == pygame.K_RETURN:
                        done=False
                    #events...
        return Text(self.game).draw_text2(self.default,word,green,wth//2,100)
项目:Pythonlearn    作者:godzoco    | 项目源码 | 文件源码
def check_events(ship):
    """???? 126 ????ship ??ship"""

    #??elif event.type == pygame.KEYDOWN:
    #???? ???? ????? ??
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
                #event.type == pygame.QUIT: ?????????
            sys.exit()
            '''???? ?? 1262?? ???????? ?????
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_RIGHT:
                ship.rect.centerx += 1
            '''
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_RIGHT:
                ship.moving_right = True
        elif event.type == pygame.KEYUP:
            if event.key == pygame.K_RIGHT:
                ship.moving_right = False
项目:Pythonlearn    作者:godzoco    | 项目源码 | 文件源码
def run_game():
# ??????????????
    pygame.init()
    #???init ?????

    #screen = pygame.display.set_mode((1200, 800))
    screen = pygame.display.set_mode((1200, 800))
    pygame.display.set_caption("?????")
    #???? ?????
    #pygame.display.set_caption("Alien Invasion")

    #??? ?? ??? ????surface,????????surface

# ????????
    #???????,??????? ?? ???? ?????? ?????
    while True:
# ?????????
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                #event.type == pygame.QUIT: ?????????
                sys.exit()
# ??????????
    #???????????? ????????? ???? ??
        pygame.display.flip()
项目:rapidpythonprogramming    作者:thecount12    | 项目源码 | 文件源码
def splash():
    intro=True
    while intro:
        for event in pygame.event.get():
            if event.type==pygame.QUIT:
                pygame.quit()
                quit()
            if event.type==pygame.KEYDOWN:
                if event.key == pygame.K_c:
                    intro=False
                if event.key==pygame.K_q:
                    pygame.quit()
                    quit()
        display.fill(white)
        message("Wellcome!!!", black,300,300 )
        message("Press 'c' to continue or 'q' to Quit",black,300,400)
        pygame.display.update()
        clock.tick(15)
项目:pool    作者:max-kov    | 项目源码 | 文件源码
def game_over(self, p1_won):
        font = config.get_default_font(config.game_over_label_font_size)
        if p1_won:
            text = "PLAYER 1 WON!"
        else:
            text = "PLAYER 2 WON!"
        rendered_text = font.render(text, False, (255, 255, 255))
        self.canvas.surface.blit(rendered_text, (config.resolution - font.size(text)) / 2)
        pygame.display.flip()
        pygame.event.clear()
        paused = True
        while paused:
            event = pygame.event.wait()
            if event.type == pygame.QUIT or event.type == pygame.KEYDOWN or event.type == pygame.MOUSEBUTTONDOWN:
                paused = False
        self.is_game_over = True
项目:team-brisket-pyweek21    作者:AjaxVM    | 项目源码 | 文件源码
def handleEvents(self, events):
        for event in events:
            if event.type == pygame.QUIT:
                self.doQuit()
                return
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    self.doQuit()
                    return

                elif event.key == pygame.K_DOWN:
                    self.current_option += 1
                    if self.current_option >= len(self.options):
                        self.current_option = 0
                elif event.key == pygame.K_UP:
                    self.current_option -= 1
                    if self.current_option < 0:
                        self.current_option = len(self.options)-1
                elif event.key == pygame.K_RETURN:
                    self.currentOptionExecute()
                    return
项目:team-brisket-pyweek21    作者:AjaxVM    | 项目源码 | 文件源码
def handleEvents(self, events):
        for event in events:
            if event.type == pygame.QUIT:
                self.game.forceQuit()
                return
            elif event.type == pygame.KEYDOWN:
                log.info('Got Key Event: '+str(event))
                if event.key == pygame.K_ESCAPE:
                    self.backToMenu()
                    return
                elif event.key in settings.CONTROLS:
                    self.doAction(settings.CONTROLS[event.key])
        held_keys = pygame.key.get_pressed()
        for key, action in settings.HELD_CONTROLS.iteritems():
            if held_keys[key]:
                self.doAction(action)
项目:Pygames    作者:christat    | 项目源码 | 文件源码
def pause():
    paused = True

    message_to_screen("PAUSED", red, -100, mfont)
    message_to_screen("Continue - [ESC]/C", white, 0, sfont)
    message_to_screen("Exit - Q", white, 50, sfont)
    pygame.display.update()

    while paused:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_c or event.key == pygame.K_ESCAPE:
                    paused = False
                elif event.key == pygame.K_q:
                    pygame.quit()
                    quit()
#        gameDisplay.fill(background)
        clock.tick(5)
项目:zeroids-16.2    作者:ProgrammaBol    | 项目源码 | 文件源码
def handle_events():
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit(0)
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_UP:
                player_one.speed = 10
            if event.key == pygame.K_RIGHT:
                player_one.angular_speed = 5
            if event.key == pygame.K_LEFT:
                player_one.angular_speed = -5
        if event.type == pygame.KEYUP:
            if event.key == pygame.K_UP:
                player_one.speed = 0
            if event.key == pygame.K_RIGHT:
                player_one.angular_speed = 0
            if event.key == pygame.K_LEFT:
                player_one.angular_speed = 0
项目:TabularSASR    作者:SimsGautam    | 项目源码 | 文件源码
def run(self):
        while not self.done:
            # if user clicks close, then exit
            for event in pygame.event.get():
                if event.type == pygame.QUIT:  
                    self.done = True
            grid = self.grid
            self.screen.fill(EMPTY_COLOR)
            for row in range(len(grid)):
                for col in range(len(grid[0])):
                    color = grid[row][col]
                    pygame.draw.rect(self.screen, color,
                                    [(MARGIN + WIDTH) * col + MARGIN,
                                     (MARGIN + HEIGHT) * row + MARGIN,
                                     WIDTH, HEIGHT])
            # Limit to 30 frames per second
            self.clock.tick(30)
            pygame.display.flip()
        pygame.quit()
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def main():
    pygame.init()
    screen = pygame.display.set_mode((500,500))
    screen.fill((255, 0, 0))
    s = pygame.Surface(screen.get_size(), pygame.SRCALPHA, 32)
    pygame.gfxdraw.aacircle(s, 250, 250, 200, (0, 0, 0))
    screen.blit(s, (0, 0))
    pygame.display.flip()
    try:
        while 1:
            event = pygame.event.wait()
            if event.type == pygame.QUIT:
                break
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE or event.unicode == 'q':
                    break
            pygame.display.flip()
    finally:
        pygame.quit()
项目:Slither    作者:PySlither    | 项目源码 | 文件源码
def runMainLoop(frameFunc):
    while True:
        blit(globalscreen)
        frameFunc()
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                if runQuitCallback():
                    # runQuitCallback would run the function
                    # given to setQuitCallback, and return its result
                    pygame.quit()
                    sys.exit()
            else:
                if event.type == pygame.KEYDOWN:
                    keysPressed.append(pygame.key.name(event.key))
                elif event.type == pygame.KEYUP:
                    keysPressed.remove(pygame.key.name(event.key))
                eventCallbacks[event.type](event)
                # eventCallbacks would be a dictionary mapping
                # event types to handler functions.
        pygame.display.flip() # Always flip at the end
        clock.tick(projectFPS) # Run at however many FPS the user specifies
项目:LastSecondSlides    作者:trishume    | 项目源码 | 文件源码
def main(to_render):
    clock = pygame.time.Clock()
    crashed = False
    slideDisplay.fill((255, 255, 255))

    while not crashed:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                crashed = True

            # print(event)

        draw_slide(to_render[0])
        # draw_90s_bullet_points("This is a title", ["FOO", "BAR", "BAZ"])
        pygame.display.update()
        time.sleep(0.1)
        # clock.tick(60)

    pygame.quit()
项目:Boardgame    作者:RensMo    | 项目源码 | 文件源码
def process_events(self):
        for event in pygame.event.get():
            if event.type == VIDEORESIZE:
                self.screen = pygame.display.set_mode(event.dict['size'], HWSURFACE | DOUBLEBUF | RESIZABLE)
                print(event.dict['size'])
                self.width = event.dict['size'][0]
                self.height = event.dict['size'][1]
            if event.type == pygame.QUIT:
                return True
            if event.type == pygame.MOUSEBUTTONUP:
                if self.b1.rect.collidepoint(pygame.mouse.get_pos()):
                    self.M0 = 1
                    self.M1 = 0 
                if self.Menu1.b1.rect.collidepoint(pygame.mouse.get_pos()):
                    self.M0 = 0
                    self.M1 = 1
                if self.Menu1.b4.rect.collidepoint(pygame.mouse.get_pos()):
                    return True

            self.b1 = Button(self.width * 0.85, self.height * 0.05, self.width * 0.1, self.height * 0.05, "Menu")
            self.Menu1 = MainMenu(self.width, self.height)

        return False
项目:sc8pr    作者:dmaccarthy    | 项目源码 | 文件源码
def run(self, quitAllowed=True):
        "Disable pygame QUIT event while running the dialog"
        set_blocked(QUIT)
        val = self.dialog(*self.args, **self.options)
        if quitAllowed: set_allowed(QUIT)
        return val
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def vPlayer( fName ):
    global ovl
    f= open( fName, 'rb' )
    fmt= f.readline().strip()
    res= f.readline().strip()
    col= f.readline().strip()
    if fmt!= "P5":
        print ('Unknown format( len %d ). Exiting...' % len( fmt ))
        return

    w,h= [ int(x) for x in res.split( ' ' ) ]
    h= ( h* 2 )/ 3
    # Read into strings
    y= f.read( w*h )
    u= []
    v= []
    for i in xrange_( 0, h/2 ):
        u.append( f.read( w/2 ))
        v.append( f.read( w/2 ))

    u= ''.join(u)
    v= ''.join(v)

    # Open overlay with the resolution specified
    ovl= pygame.Overlay(pygame.YV12_OVERLAY, (w,h))
    ovl.set_location(0, 0, w, h)

    ovl.display((y,u,v))
    while 1:
        pygame.time.wait(10)
        for ev in pygame.event.get():
            if ev.type in (pygame.KEYDOWN, pygame.QUIT): 
                return
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def show (image):
    screen = pygame.display.get_surface()
    screen.fill ((255, 255, 255))
    screen.blit (image, (0, 0))
    pygame.display.flip ()
    while 1:
        event = pygame.event.wait ()
        if event.type == pygame.QUIT:
            raise SystemExit
        if event.type == pygame.MOUSEBUTTONDOWN:
            break
项目:pygame_cards    作者:vannov    | 项目源码 | 文件源码
def process_events(self):
        """ Processes mouse events and quit event """
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                self.stopped = True
                self.render_thread.join()
                self.game_controller.cleanup()
                sys.exit()
            elif event.type == pygame.MOUSEBUTTONUP:
                self.process_mouse_event(False, self.is_double_click())
            elif event.type == pygame.MOUSEBUTTONDOWN:
                self.process_mouse_event(True)
项目:alien_invasion    作者:samnew    | 项目源码 | 文件源码
def check_events(ai_settings, screen, stats, sb, play_button, ship, aliens, bullets):
    """?????????"""
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            stats.save_high_score()
            sys.exit()

        elif event.type == pygame.KEYDOWN:
            check_keydown_events(event, ai_settings, screen, stats,sb, ship, aliens, bullets)
        elif event.type == pygame.KEYUP:
            check_keyup_events(event, ship)
        elif event.type == pygame.MOUSEBUTTONDOWN:
            mouse_x, mouse_y = pygame.mouse.get_pos()
            check_play_button(ai_settings, screen, stats, sb, play_button, ship, aliens, bullets, mouse_x, mouse_y)
项目:opseilen    作者:Baal221    | 项目源码 | 文件源码
def Update(self):
        events = pygame.event.get()
        for event in events:            
            if event.type == pygame.QUIT:
              sys.exit()
        for button in self.Buttons:
            res = button.Update(events)
            if (res != button):
                return res
        return self
项目:opseilen    作者:Baal221    | 项目源码 | 文件源码
def Update(self):
        events = pygame.event.get()
        for event in events:            
            if event.type == pygame.QUIT:
                sys.exit()
        for button in self.Buttons:
            res = button.Update(events)
            if (res != button):
                return res
        return self
项目:opseilen    作者:Baal221    | 项目源码 | 文件源码
def __init__(self, width, height):
        self.Width = width
        self.Height = height        
        self.Image = pygame.image.load(os.path.join('project2/euromast_illustratie_02.jpg'))
        self.Buttons = [Button("PLAY", 250, 40, lambda : game.Game().program_loop()),
                        #Button("LOAD SAVE GAME", 250, 80, lambda: [game.Game().program_loop(), other.SaveGame.load()]),
                        Button("INSTRUCTIONS", 250, 110, lambda : InstructionMenu(width, height)),
                        Button("HIGH SCORE", 250, 180, lambda : HighScoreMenu(width, height)),
                        Button("QUIT", 250, 250, lambda : sys.exit())]
项目:opseilen    作者:Baal221    | 项目源码 | 文件源码
def Update(self):
        events = pygame.event.get()
        for event in events:            
            if event.type == pygame.QUIT:
              sys.exit()
        for button in self.Buttons:
            res = button.Update(events)
            if (res != button):
                return res
        return self
项目:opseilen    作者:Baal221    | 项目源码 | 文件源码
def process_events():
        for event in pygame.event.get():
                if event.type == pygame.QUIT:
                        sys.exit()
        return False


# Main game logic
项目:PyCut    作者:FOSSRIT    | 项目源码 | 文件源码
def _quit_cb(self, data=None):
        self.__stopped = True
        pygame.event.post(pygame.event.Event(pygame.QUIT))
项目:pyclimber    作者:manixaist    | 项目源码 | 文件源码
def check_events(settings, screen, tile_map):
    """Watch for keyboard and mouse events"""
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()

        elif event.type == pygame.KEYDOWN:
            check_keydown_events(settings, event, screen, tile_map)
        elif event.type == pygame.KEYUP:
            check_keyup_events(settings, event, screen, tile_map)
项目:satellite-tracker    作者:lofaldli    | 项目源码 | 文件源码
def main_loop(self, callback=None, run_once=False):

        while True:

            for e in pg.event.get():
                if e.type == pg.QUIT:
                    sys.exit()

            if callback:
                self.data = callback()

            self.update()
            if run_once:
                sys.exit()
项目:cs6244_motionplanning    作者:chenmin1107    | 项目源码 | 文件源码
def keyboard_loop(self):
        while not rospy.is_shutdown():
            acc = 0
            yaw = 0

            keys = pygame.key.get_pressed()
            for event in pygame.event.get():
                if event.type==pygame.QUIT:sys.exit()

            if(keys[pygame.K_s]):
                self.send_highway_start(1)

            if(keys[pygame.K_t]):
                self.send_highway_start(2)

            if(keys[pygame.K_UP]):
                acc = self.acc
            elif(keys[pygame.K_DOWN]):
                acc = -self.acc
            if(keys[pygame.K_LEFT]):
                yaw = self.yaw
            elif(keys[pygame.K_RIGHT]):
                yaw = -self.yaw
            if(keys[pygame.K_r]):
                state = 1
                self.send_record_state(state)
            elif(keys[pygame.K_q]):
                state = 2
                self.send_record_state(state)
            elif(keys[pygame.K_p]):
                state = 0
                self.send_record_state(state)

            self.send_control(acc, yaw)
            self.rate.sleep()