I wanted to try out pyglet for making a multi-windowed app, and i got it working (sorta) My goal was to make it so you can move the windows around freely and have the squares stay still relative to the screen.
import pyglet
class window():
def __init__(self, width, height) -> None:
pyglet.clock.tick()
self.screen = pyglet.window.Window(width, height)
self.x = self.screen.get_location()[0]
self.y = self.screen.get_location()[1]
self.width = width
self.height = height
self.items = [
pyglet.shapes.Rectangle(x=500, y=600, width=200, height=200, color=(55, 55, 255)), #square1
pyglet.shapes.Rectangle(x=680, y=300, width=50, height=50, color=(55, 55, 255)) #square2
]
@self.screen.event
def on_draw():
self.drawObjects()
@self.screen.event
def on_move(x, y):
self.x = x
self.y = y
self.drawObjects()
self.screen.flip()
print(f"moved to {x}, {y}")
def drawObjects(self):
self.screen.clear()
for item in self.items:
position = self.alignObject(item)
pyglet.shapes.Rectangle(x=position[0], y=position[1], width=50, height=60, color=(30, 50, 70)).draw()
def alignObject(self, object):
return (object.x-self.x, self.screen.get_size()[1]-object.y+self.y)
win1 = window(500, 500)
win2 = window(300, 300)
pyglet.app.run()
I think it's working how it should be position and math wise, but only win1 updates properly, win2 only updates itself after letting go. I also tried implementing a clock.schedule_interval however this only made things worse.
Has this something to do with me using the same class for both windows, or is this not how you make two windows using pyglet.
All help appreciated :)