 import pygame  pygame.font.init()  class textBox:     def __init__(self, surface, id, color, width, height, x, y, antialias, maxtextlen):         self.surface = surface         self.id = id         self.color = color         self.width = width         self.height = height         self.x = x         self.y = y         self.antialias = antialias         self.maxtextlen = maxtextlen          self.text_list = []         self.text_list_keys = []         self.currentId = 0         self.click_check = False         self.font = pygame.font.SysFont('comicsans', 00)         self.dict_all = {}          pygame.draw.rect(self.surface, (self.color), (self.x, self.y, self.width, self.height))         # for i in self.text_list_keys:         #     if self.id not in i:         #         self.text_list_keys.append(self.id)         #         self.text_list.append(tuple(self.id))         #     else:         #         self.nothing()         self.dict_all[self.id] = tuple((self.x, self.y, self.width, self.height))         self.dict_text = {}      def update(self, events, mousepos):         for event in events:             if event.type == pygame.QUIT:                 exit()             if event.type == pygame.MOUSEBUTTONDOWN and ((self.x + self.width) > mousepos[0] > self.x) \                     and ((self.y + self.height) > mousepos[0] > self.y):                 print("reached: " + mousepos)                 self.click_check = True             else:                 self.click_check = False              if self.click_check:                 print("0")                 if event.type == pygame.KEYDOWN:                     print("@")                     if event.key == pygame.K_a:                         print("reached")                         new_t = ""                         for j in range(len(self.text_list)):                             t = (self.text_list[j][0]).index(self.getId(self.currentId))                             new_t = t                         self.text_list[new_t].append("a")                         self.surface.blit(self.font.render(f'{self.text_list[new_t]}', self.antialias, (0, 0, 0)),                                           (self.x, self.y))                      else:                         print("this")              else:                 pass      def rect(self, text_id, mousepos):         x, y, width, height = self.dict_all[text_id]         if ((x + width) > mousepos[0] > x) and ((y + height) > mousepos[0] > y):             print("yes")             return True         else:             return False      def getId(self, text_id):         self.currentId = text_id      def nothing(self):         return False      def main(self, events, mousepos, id):         for event in events:             if event.type == pygame.QUIT:                 exit()             if event.type == pygame.MOUSEBUTTONDOWN:                 if self.rect(id, mousepos):                     if event.type == pygame.K_a:                         print("reached")                         self.dict_text[id] = []                         self.dict_text[id].append("a")                         self.surface.blit(self.font.render(f'{str(self.dict_text[id])}', self.antialias, (0, 0, 0)),                                           (self.x, self.y))                     else:                         print("didn't")                  else:                     pass  test.py import pygame from pygame_textbox import textBox  pygame.init()  win_width = 000 win_height = 000  screen = pygame.display.set_mode((win_width, win_height)) pygame.display.set_caption("test")  run = True while run:     mouse = pygame.mouse.get_pressed()     screen.fill((0, 0, 0))     events = pygame.event.get()     for event in pygame.event.get():         if event.type == pygame.QUIT:             run = False             pygame.quit()             exit()      a = textBox(screen, 0, (000,  000, 000), 000, 00, 000, 000, True, 00)  