Python pygame 模块,K_b() 实例源码

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

项目: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)
项目:nautical-combat    作者:horstjens    | 项目源码 | 文件源码
def run(self):
        """The mainloop"""

        running = True
        while running:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    running = False 
                elif event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        running = False
                    #if event.key == pygame.K_b:
                      #  self.ballgroup.append(Ball()) # add balls!
            # end of event handler
           # milliseconds = self.clock.tick(self.fps) #
           # seconds = milliseconds / 1000
           # self.playtime += seconds
            # delete everything on screen
            self.screen.blit(self.background, (0, 0)) 
            # write text below sprites
            #write(self.screen, "FPS: {:6.3}  PLAYTIME: {:6.3} SECONDS".format(
            #               self.clock.get_fps(), self.playtime))
            # not-pygame-sprites
            #for myball in self.ballgroup:
            #    myball.update(seconds)
            #for myball in self.ballgroup:
            #    myball.blit(self.screen)
            # write text over everything 
            #write(self.screen, "Press b to add another ball", x=self.width//2, y=250, center=True)
            # next frame
            pygame.display.flip()

        pygame.quit()