Search code examples
pythonpyglet

Did pyglet change recently?


So, The other day, I went back to an old project to finish it but when I tried running it, it gave me several errors that I've tried to fix but some of them I don't know how to fix. The program worked fine when I stopped working on it, so I'm very confused at what happened. My guess is that pyglet got a new update and removed a lot of stuff I used to use. Some of the errors I get are as follows

Traceback (most recent call last):
  File "C:\Users\____\Desktop\Code\3D\Projects\3D Program 1\main.py", line 9, 
in <module>
    screen = 
pyglet.window.get_platform().get_default_display().get_default_screen()
AttributeError: module 'pyglet.window' has no attribute 'get_platform'

and

Traceback (most recent call last):
  File "C:\Users\____\Desktop\Code\3D\Projects\3D Program 1\main.py", line 216, in <module>
    main()
  File "C:\Users\____\Desktop\Code\3D\Projects\3D Program 1\main.py", line 208, in main
    win = Window(caption = "3D Program 1", width = WINW, height = WINH, resizable = False, vsync = True)
  File "C:\Users\____\Desktop\Code\3D\Projects\3D Program 1\main.py", line 57, in __init__
    self.tex1 = get_tex("steel_tex.png")
  File "C:\Users\____\Desktop\Code\3D\Projects\3D Program 1\main.py", line 21, in get_tex
    tex = pyglet.image.load(file).texture
AttributeError: 'ImageData' object has no attribute 'texture'

I also had problems with it saying that there was no such thing as the "pyglet.graphics.TextureGroup" class


Solution

  • Yes, it looks like both of snippets of code you show are using features that were deprecated in previous versions of Pyglet and removed in the recent 1.4 release. You can see the deprecation (and their suggested replacements) in the documentation for older versions:

    The get_platform() function in pyglet.window:

    Deprecated. Use pyglet.canvas.Display.

    The .texture attribute of an image:

    Deprecated. Use get_texture().