Created
October 24, 2023 02:13
-
-
Save pushfoo/c313fcefdcdccbeda38d3614d5f75f72 to your computer and use it in GitHub Desktop.
Replication code for a pyglet crash involving RGB colors & underlines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyglet | |
COLOR = (255, 255, 255, 255) # RGB values will crash the code | |
LINE_HEIGHT_PX=40 | |
FONT_SIZE_PT=20 | |
TEXT="Test" | |
TAG='b' # u sets it off, but b does not | |
def html(tag, contents): | |
return f"<{tag}>{contents}</{tag}>" | |
window = pyglet.window.Window(200,200) | |
batch = pyglet.graphics.Batch() | |
@window.event | |
def on_draw(): | |
window.clear() | |
batch.draw() | |
shared_data = dict(x=window.height // 2, batch=batch) | |
label_data = [ | |
(pyglet.text.Label, [TEXT] , dict(bold=True, font_size=FONT_SIZE_PT)), | |
(pyglet.text.HTMLLabel, [html(TAG, TEXT)], {} ) | |
] | |
label_instances = [] | |
current_y = (window.height // 2) - (len(label_data) // 2) * 20 | |
for label_class, args, kwargs in label_data: | |
label = label_class(*args, y=current_y, **shared_data, **kwargs) | |
label.color = COLOR | |
label_instances.append(label) | |
current_y += LINE_HEIGHT_PX | |
pyglet.app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment