Pyglet不显示文本:
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()我正在使用:Python3.6.9
pip安装中最新的pyglet
内部码头运行Ubuntu 18
屏幕完全是白色/空白的。我可以正确渲染所有的形状,只是没有文字。
发布于 2022-05-16 17:29:06
字体大小以像素为单位,(0,0)位于窗口左侧的底部。对文本的原点使用不同的字体大小和坐标:
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)

https://stackoverflow.com/questions/72253068
复制相似问题