Locking the size of a resizable window to the original aspect ratio of the window in Pyglet

StackOverflow https://stackoverflow.com/questions/18682362

  •  28-06-2022
  •  | 
  •  

Question

I'm making an image viewer, and I want it to resize only to scale factors of the original image size. In short, on resize, I want the entire image visible and no whitespace in the window. Is there any way to do this in pyglet? I've tried using the window.set_size() function, but I can't exactly figure out how to word the code so that it works the way I want it to. Any help is appreciated.

Was it helpful?

Solution

Although this looks a little hackish for me, but at the moment I don't think of any other possibilities to solve you problem. Anyway, this is working:

import pyglet

window = pyglet.window.Window( resizable=True )

@window.event
def on_resize( width, height ):
    ratio = 9/16
    window.set_size( width, width*ratio )

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

pyglet.app.run()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top