pyglet在M中没有按预期运行

2024-04-26 14:55:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我用pyglet实现简单的文本翻译。当window = pyglet.window.Window()中没有添加config时,它可以完美地工作。但是,在第8行中添加config之后,代码不会运行。我用的是Mac High Sierra。在

import pyglet

platform = pyglet.window.get_platform()
display = platform.get_default_display()
screen = display.get_default_screen()
template = pyglet.gl.Config()
config = screen.get_best_config(template)
window = pyglet.window.Window(config=config)
label = pyglet.text.Label('Hello, world', x=window.width//2, y=window.height//2,
                          anchor_x='center', anchor_y='center')

def update(dt):
  #print(dt) # time elapsed since last time we were called
  label.x += 1
  label.y += 1

@window.event
def on_draw():
  window.clear()
  label.draw()

pyglet.clock.schedule(update) # cause a timed event as fast as you can!
pyglet.app.run()

Tags: configdefaultgetdefdisplayupdatetemplatewindow
1条回答
网友
1楼 · 发布于 2024-04-26 14:55:33

尝试从窗口配置中定义配置,请尝试以下操作:

import pyglet
window = pyglet.window.Window()
context = window.context
#config = context.config
platform = pyglet.window.get_platform()
display = platform.get_default_display()
screen = display.get_default_screen()
config = screen.get_best_config()#if you need best config although if you add template as an argument it forms a deadlock.
template = pyglet.gl.Config(config=config)
#config = screen.get_best_config(template)
label = pyglet.text.Label('Hello, world', x=window.width//2, y=window.height//2,
                          anchor_x='center', anchor_y='center')

def update(dt):
  #print(dt) # time elapsed since last time we were called
  label.x += 1
  label.y += 1

@window.event
def on_draw():
  window.clear()
  label.draw()

pyglet.clock.schedule(update) # cause a timed event as fast as you can!
pyglet.app.run()

相关问题 更多 >