--- /dev/null
+""" Buttons. """
+
+from pgzero.ptext import getsurf
+from .surf import SurfActor
+
+
+class TextButton(SurfActor):
+ def __init__(self, text, **kwargs):
+ super(TextButton, self).__init__(getsurf(text, **kwargs))
+
+ def text(self, *args, **kw):
+ self.surf = getsurf(*args, **kw)
--- /dev/null
+""" Actor that takes a surface. """
+
+from pgzero.actor import Actor, POS_TOPLEFT, ANCHOR_CENTER
+
+
+class SurfActor(Actor):
+ def __init__(self, surf, pos=POS_TOPLEFT, anchor=ANCHOR_CENTER, **kwargs):
+ self._handle_unexpected_kwargs(kwargs)
+
+ self.surf = surf
+ # Initialise it at (0,0). We'll move it to the right place later
+ super(Actor, self).__init__((0, 0), self._surf.get_size())
+
+ self._init_position(pos, anchor, **kwargs)
+
+ def _update_pos(self):
+ p = self.pos
+ self.width, self.height = self._surf.get_size()
+ self._calc_anchor()
+ self.pos = p
+
+ @property
+ def surf(self):
+ """ The original surface displaying the actor. """
+ return self._orig_surf
+
+ @surf.setter
+ def surf(self, surf):
+ self._orig_surf = self._surf = surf
+ self._update_pos()