Difficult-Rocket/try/pyglet check/html files.py

44 lines
1.0 KiB
Python
Raw Normal View History

2021-12-15 23:28:08 +08:00
"""A simple demonstration of the HTMLLabel class, as it might be used on a
help or introductory screen.
"""
import os
import pyglet
html = '''
<h1>HTML labels in pyglet</h1>
<p>HTML labels are a simple way to add formatted text to your application.
Different <font face="Cascadia Code" size=+2>fonts</font>, <em>styles</em>
and <font color=red>colours</font> are supported.
<p>This window has been made resizable; text will reflow to fit the new size.
'''
window = pyglet.window.Window(resizable=True)
location = pyglet.resource.FileLocation(os.path.dirname(__file__))
label = pyglet.text.HTMLLabel(html, location=location,
width=window.width,
multiline=True, anchor_y='center')
@window.event
def on_resize(width, height):
# Wrap text to the width of the window
label.width = window.width
# Keep text vertically centered in the window
label.y = window.height // 2
@window.event
def on_draw():
window.clear()
label.draw()
pyglet.gl.glClearColor(1, 1, 1, 1)
pyglet.app.run()