pygame login page frontend errors

Viewed 71

I tried to make a login page using pygame and firebase but this front-end code when i run it the backspace and return are not working and also when i type in one box the other also gets the input could anyone help me with it so that i can print the info and use firebase sign in command.

def auth(self):

    self.E_select = False
    self.P_select = False

    while True:
        self.screen.fill((0, 0, 0))

        pygame.draw.rect(self.screen, self.RECT_C, (140, 250, 470, 50), 2)
        self.draw_text(self.screen, self.email, 274, 26, (250, 250, 250))

        pygame.draw.rect(self.screen, self.RECT_C, (140, 320, 470, 50), 2)
        self.draw_text(self.screen, self.pwd, 345, 26, (250, 250, 250))

        pygame.display.update()
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
            elif event.type == MOUSEBUTTONUP:
                x, y = pygame.mouse.get_pos()
                if(x>=140 and x<=470 and y>=250 and y<=300):
                    self.E_select=True
                    self.email=''
                elif(x>=140 and x<=470 and y>=320 and y<=370):
                    self.P_select=True
                    self.pwd=''
            elif event.type == pygame.KEYDOWN:
                if not self.end:
                    if event.type == pygame.K_RETURN :
                        if self.E_select:
                            print(self.email)
                            self.email=''
                        elif self.P_select:
                            print(self.pwd)
                            self.pwd=''

                    elif event.type == pygame.K_BACKSPACE:
                        if self.E_select:
                            self.email = self.email[:-1]
                        elif self.P_select:
                            self.pwd = self.pwd[:-1]

                    else:
                        if self.E_select:
                            self.email += event.unicode
                        elif self.P_select:
                            self.pwd += event.unicode

        pygame.display.update()
1 Answers

If you want to check the key pressed for a KEYDOWN event then you're looking for event.key, e.g., if event.key == pygame.K_RETURN (and not if event.type == pygame.K_RETURN).

Related