首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Pyglet不显示文本

Pyglet不显示文本
EN

Stack Overflow用户
提问于 2022-05-16 00:18:12
回答 1查看 58关注 0票数 1

Pyglet不显示文本:

代码语言:javascript
复制
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

屏幕完全是白色/空白的。我可以正确渲染所有的形状,只是没有文字。

EN

回答 1

Stack Overflow用户

发布于 2022-05-16 17:29:06

字体大小以像素为单位,(0,0)位于窗口左侧的底部。对文本的原点使用不同的字体大小和坐标:

代码语言:javascript
复制
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)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72253068

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档