I want to use a variable to access an attribute of an object created by a class, but Python uses the variable's name as a the object's name and not the name stored in the variable.
class button():
def __init__(self, color, x, y, width, height, text=''):
self.color = color
self.x = x
self.y = y
self.width = width
self.height = height
self.text = text
white = (255,255,255).
A1 = button(white, 50, 50, 20, 20, text='Hello World')
var = "A1"
print(var.text)
And when I run it:
AttributeError: 'str' object has no attribute 'text'
Is there any way to use the information inside var
as the object name when calling var.text
?