| 1 |
"""A simple demonstration of the HTMLLabel class, as it might be used on a |
| 2 |
help or introductory screen. |
| 3 |
""" |
| 4 |
|
| 5 |
import os |
| 6 |
import pyglet |
| 7 |
|
| 8 |
html = """ |
| 9 |
<h1>HTML labels in pyglet</h1> |
| 10 |
|
| 11 |
<p align="center"><img src="pyglet.png" /></p> |
| 12 |
|
| 13 |
<p>HTML labels are a simple way to add formatted text to your application. |
| 14 |
Different <font face="Helvetica,Arial" size=+2>fonts</font>, <em>styles</em>, |
| 15 |
<u>underlines</u>, and <font color=maroon>colours</font> are supported. |
| 16 |
|
| 17 |
<p>This window has been made resizable; text will reflow to fit the new size. |
| 18 |
""" |
| 19 |
|
| 20 |
window = pyglet.window.Window(resizable=True) |
| 21 |
location = pyglet.resource.FileLocation(os.path.dirname(__file__)) |
| 22 |
label = pyglet.text.HTMLLabel(html, location=location, |
| 23 |
width=window.width, |
| 24 |
multiline=True, anchor_y='center') |
| 25 |
|
| 26 |
|
| 27 |
@window.event |
| 28 |
def on_resize(width, height): |
| 29 |
|
| 30 |
label.width = window.width |
| 31 |
|
| 32 |
|
| 33 |
label.y = window.height // 2 |
| 34 |
|
| 35 |
|
| 36 |
@window.event |
| 37 |
def on_draw(): |
| 38 |
window.clear() |
| 39 |
label.draw() |
| 40 |
|
| 41 |
|
| 42 |
pyglet.gl.glClearColor(1, 1, 1, 1) |
| 43 |
pyglet.app.run() |