0

Backstory: I wanted to try and make my first ever Pygame so I wanted to make buttons on the screen for all the alphabet letters so I made a class called buttons and wanted a for loop that will create all the buttons then in the while loop that you use in Pygame I could show all of them on the screen

What I want to do: I want to create classes and I want the classes names to be from a to z

list = ['a', 'b', 'c' etc..]

class Example():
def __init__(self, letter):
   self.letter = letter
def paste():
   print(self.letter)

# pasting all of the letters
def pasteall():
   for i in range(len(list)):
      letter = list[i]
      letter.print()

# creating the variables
for i in range(len(list)):
   letter = list[i]
   letter = Example()

But I want the variable to be named 'a' 'b' 'c' etc... And then in the pasteall I want it to print all of the new created variables.

Rabbid76
  • 177,135
  • 25
  • 101
  • 146
  • so you can do `locals()[letter] = Example()` to set the variable with that name, but there's probably better ways to get those 26 buttons on screen – ddg Jan 31 '21 at 03:56
  • Does this answer your question? [How do I create variable variables?](https://stackoverflow.com/questions/1373164/how-do-i-create-variable-variables) – python_user Jan 31 '21 at 04:01

0 Answers0