class ChooseName: def __init__(self, screen, background): self.width = screen.get_width() self.height = screen.get_height() self.textboxW = 300 self.textboxH = 60 self.tScreenCenterX = self.width / 2 - self.textboxW / 2 self.tScreenCenterY = self.height / 2 - self.textboxH / 2 self.image = background myfont = pygame.font.Font("prstartk.ttf", 40) self.input = Textbox( (self.tScreenCenterX, self.tScreenCenterY, self.textboxW, self.textboxH), clear_on_enter=True, inactive_on_enter=False, ) self.label = myfont.render("Please Enter Your Name", 1, (0, 0, 0)) self.textRect = self.label.get_rect() self.textRect.centerx = self.width / 2 self.textRect.centery = self.height / 2.5 def Run(self, screen): mainloop = True while mainloop: screen.blit(self.image, (0, 0)) screen.blit(self.label, self.textRect) for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == pygame.KEYDOWN: if event.key == K_q: pygame.quit() sys.exit() textboxEvents = self.input.getEvent(event) if textboxEvents is not None: screen.blit(self.image, (0, 0)) mainloop = False return textboxEvents self.input.update() self.input.draw(screen) pygame.display.update()
def __init__(self, screen, background): self.width = screen.get_width() self.height = screen.get_height() self.textboxW = 300 self.textboxH = 60 self.tScreenCenterX = self.width / 2 - self.textboxW / 2 self.tScreenCenterY = self.height / 2 - self.textboxH / 2 self.image = background myfont = pygame.font.Font("prstartk.ttf", 40) self.input = Textbox( (self.tScreenCenterX, self.tScreenCenterY, self.textboxW, self.textboxH), clear_on_enter=True, inactive_on_enter=False, ) self.label = myfont.render("Please Enter Your Name", 1, (0, 0, 0)) self.textRect = self.label.get_rect() self.textRect.centerx = self.width / 2 self.textRect.centery = self.height / 2.5