我正在使用OpenAI Gym的包装器来创建问题的图形表示。为此,我使用给定的包装纸绘制了一个圆圈,然后尝试添加一些文本。
我的问题是,仅显示圆圈,但未显示文本标签。我将如何使文本可见的任何建议将不胜感激。在一个最小的示例下面,它显示了问题:
{
error = {
code = BadRequest,
innerError = {
date = 2019 - 06 - 24 T20: 40: 52,
request - id = #####################
},
message = Unable to read JSON request payload.Please ensure Content - Type header is set and payload is of valid JSON format.
}
}
答案 0 :(得分:0)
请尝试以下代码:
import pyglet
from gym.envs.classic_control import rendering
class DrawText:
def __init__(self, label:pyglet.text.Label):
self.label=label
def render(self):
self.label.draw()
screen_width = 600
screen_height = 400
table_radius = 200
viewer = rendering.Viewer(screen_width, screen_height + 20)
table = rendering.make_circle(radius=table_radius, filled=False)
table_trans = rendering.Transform()
table.add_attr(table_trans)
table_trans.set_translation(screen_width / 2, screen_height / 2)
viewer.add_geom(table)
text = 'This is a test but it is not visible'
label = pyglet.text.Label(text, font_size=36,
x=10, y=10, anchor_x='left', anchor_y='bottom',
color=(255, 123, 255, 255))
label.draw()
viewer.add_geom(DrawText(label))
viewer.render(return_rgb_array=False)
input()
答案 1 :(得分:0)
对我有用的是手动实现render函数,并在tranform.disable()之后插入标签
{{1}}