pygame_functions.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:Pygame_Functions 作者: StevePaget 项目源码 文件源码
def update(self, keyevent):
        key = keyevent.key
        unicode = keyevent.unicode
        if key > 31 and key < 127 and (
            self.maxLength == 0 or len(self.text) < self.maxLength):  # only printable characters
            if keyevent.mod == 1 and self.case == 1 and key >= 97 and key <= 122:
                # force lowercase letters
                key -= 32
                self.text += chr(key)
            else:
                # use the unicode char
                self.text += unicode
        elif key == 8:
            # backspace. repeat until clear
            keys = pygame.key.get_pressed()
            nexttime = pygame.time.get_ticks() + 200
            deleting = True
            while deleting:
                keys = pygame.key.get_pressed()
                if keys[pygame.K_BACKSPACE]:
                    thistime = pygame.time.get_ticks()
                    if thistime > nexttime:
                        self.text = self.text[0:len(self.text) - 1]
                        self.image.fill((255, 255, 255))
                        pygame.draw.rect(self.image, (0, 0, 0), [0, 0, self.width - 1, self.boxSize - 1], 2)
                        newSurface = self.font.render(self.text, True, self.fontColour)
                        self.image.blit(newSurface, [10, 5])
                        updateDisplay()
                        nexttime = thistime + 50
                        pygame.event.clear()
                else:
                    deleting = False

        self.image.fill((255, 255, 255))
        pygame.draw.rect(self.image, (0, 0, 0), [0, 0, self.width - 1, self.boxSize - 1], 2)
        newSurface = self.font.render(self.text, True, self.fontColour)
        self.image.blit(newSurface, [10, 5])
        updateDisplay()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号