File: window_subclass.py

package info (click to toggle)
pyglet 2.0.17%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 15,560 kB
  • sloc: python: 80,579; xml: 50,988; ansic: 171; makefile: 146
file content (22 lines) | stat: -rwxr-xr-x 573 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python
"""Demonstrates a useful pattern for pyglet applications: subclassing Window.
"""

import pyglet


class HelloWorldWindow(pyglet.window.Window):
    def __init__(self):
        super().__init__()
        self.label = pyglet.text.Label('Hello, world!', font_size=36,
                                       x=self.width//2, y=self.height//2,
                                       anchor_x='center')

    def on_draw(self):
        self.clear()
        self.label.draw()


if __name__ == '__main__':
    window = HelloWorldWindow()
    pyglet.app.run()