我试图使用pygame
和firebase
创建一个登录页面,但当我运行这个前端代码时,退格和返回都不起作用,而且当我在一个框中键入时,另一个框也得到了输入。有人能帮我吗?这样我就可以打印信息并使用firebase
登录命令。
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()
如果要检查按下的键是否有KEYDOWN
事件,则要查找event.key
,例如if event.key == pygame.K_RETURN
(而不是if event.type == pygame.K_RETURN
(。