Pyglet does not show text:
import pyglet
from pyglet import shapes
from src.utils.pyglet_util import draw_coordinate_axises, draw_rect,draw_circle
window_width= 960
window_height = 960*2
window = pyglet.window.Window(window_width, window_height)
pyglet.gl.glClearColor(1,1,1,1)
batch = pyglet.graphics.Batch()
shapes_arr = []
# circle = shapes.Circle(700, 150, 100, color=(50, 225, 30), batch=batch)
# square = shapes.Rectangle(200, 200, 200, 200, color=(55, 55, 255), batch=batch)
# rectangle = shapes.Rectangle(250, 300, 400, 200, color=(255, 22, 20), batch=batch)
# rectangle.opacity = 128
# rectangle.rotation = 33
# line = shapes.Line(100, 100, 100, 200, width=19, color=(0, 100, 20), batch=batch)
# line2 = shapes.Line(150, 150, 444, 111, width=4, color=(200, 20, 20), batch=batch)
# star = shapes.Star(800, 400, 60, 40, num_spikes=20, color=(255, 255, 0), batch=batch)
@window.event
def on_draw():
window.clear()
batch.draw()
# shapes_arr.append(draw_coordinate_axises(window_width, window_height, batch))
# shapes_arr.append(draw_rect(0, 10 / 2, 10, 10, window_width, window_height, scale=10, batch=batch))
#
# shapes_arr.append(shapes.Circle(10, 10, 10, color=(100, 0, 0), batch=batch))
label = pyglet.text.Label(f"tesroirjesoirjoifjiofjioj",
font_size=4000,
# x=witness_var[2*idx][0]*scale, y=witness_var[2*idx][1] * scale,
x=50, y=50,
anchor_x='center', anchor_y='center', batch=batch,
width=10,
height=10)
label.color = (255, 0, 0, 255)
pyglet.app.run()
I am using: Python 3.6.9
Latest pyglet from pip install
Inside Docker running Ubuntu 18
The screen is totally white/blank. I can render all of the shapes properly, just no text.
The font size is measured in pixels and (0, 0) is at the bottom left of the window. Use a different font size and coordinates for the origin of the text:
label = pyglet.text.Label(
f"Hello world",
font_size=50,
x=50, y= window.height-50,
anchor_x='left', anchor_y='center', batch=batch,
width=10, height=10)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.