我刚刚在我的机器上安装了 pyglet。但我似乎无法创建一个窗口
这是我试过的
import pyglet
window = pyglet.window.Window()
pyglet.app.run()
当我运行时它给了我这个错误
Traceback (most recent call last):
File "c:/Users/Public/Documents/vscode/python/Games/Pyglet/main.py", line 3, in <module>
window = pyglet.window.Window()
File "C:\Users\DELL\AppData\Roaming\Python\Python38\site-packages\pyglet\window\win32\__init__.py", line 132, in __init__
super(Win32Window, self).__init__(*args, **kwargs)
File "C:\Users\DELL\AppData\Roaming\Python\Python38\site-packages\pyglet\window\__init__.py", line 648, in __init__
self._create()
File "C:\Users\DELL\AppData\Roaming\Python\Python38\site-packages\pyglet\window\win32\__init__.py", line 274, in _create
self.context.attach(self.canvas)
File "C:\Users\DELL\AppData\Roaming\Python\Python38\site-packages\pyglet\gl\win32.py", line 238, in attach
raise gl.ContextException('Unable to share contexts.')
pyglet.gl.ContextException: Unable to share contexts.
也许这会对某些人有所帮助,过去 2 天我在一些论坛上进行了搜索,似乎 Intel HD 4000 有问题,它有点破坏了 pyglet。 这是我找到的解决方案,只需更改“\gl\win32.py”中的方法 create_context 即可:
def create_context(self, share):
if wgl_info.have_extension('WGL_ARB_create_context') and gl_info.get_vendor() != 'Intel':
return Win32ARBContext(self, share)
else:
return Win32Context(self, share)
希望它有效!!