Dragging Pyglet window on anywhere

Viewed 21

I was making a game with pyglet, and I decided to make window draggable on anywhere (In detail, you can drag window by clicking anywhere on the window, not only top bar of the window) However, the window flickered between two positions when I dragged it.

How can I solve it?

Here is the code:

import pyglet

class Window(pyglet.window.Window):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
    def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
        winpos = self.get_location()
        self.set_location(winpos[0] + dx, winpos[1] - dy)

if __name__ == "__main__":
    win = Window(400, 300)
    pyglet.app.run()
0 Answers
Related