[英]pyglet not running as expected in MacOS
我正在使用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()
嘗試從窗口配置中定義配置,請嘗試以下操作:
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()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.