| 1 | #!/usr/bin/env python |
| 2 | """Demonstrates a useful pattern for pyglet applications: subclassing Window. |
| 3 | """ |
| 4 | |
| 5 | import pyglet |
| 6 | |
| 7 | |
| 8 | class HelloWorldWindow(pyglet.window.Window): |
| 9 | def __init__(self): |
| 10 | super().__init__() |
| 11 | self.label = pyglet.text.Label('Hello, world!', font_size=36, |
| 12 | x=self.width//2, y=self.height//2, |
| 13 | anchor_x='center') |
| 14 | |
| 15 | def on_draw(self): |
| 16 | self.clear() |
| 17 | self.label.draw() |
| 18 | |
| 19 | |
| 20 | if __name__ == '__main__': |
| 21 | window = HelloWorldWindow() |
| 22 | pyglet.app.run() |