jonwright / pyopengltk

OpenGL frame for Python/Tkinter via ctypes and pyopengl
MIT License
52 stars 14 forks source link

OpenglFrame only takes mouse input tkinter binds and not kebaord binds. #27

Open ShaunKulesa opened 3 years ago

ShaunKulesa commented 3 years ago

I have noticed that the openglframe supports <Enter> and <MouseWheel> but not any keyboard input. Is this something that can be changed?.

einarf commented 3 years ago

Works fine for me in moderngl-window

self._tk.bind("<KeyPress>", self.tk_key_press)
self._tk.bind("<KeyRelease>", self.tk_key_release)

Signature of callback methods are:

def tk_key_press(self, event: tkinter.Event) -> None:
def tk_key_release(self, event: tkinter.Event) -> None:

Or do you mean adding native support for it?

ShaunKulesa commented 3 years ago

app.bind("<KeyPress>", sys.exit) does not work at all, but mouse inputs do.

einarf commented 3 years ago

app.bind("<KeyPress>", sys.exit) does not work at all, but mouse inputs do.

I would never assume this actually working. tkinter might be discarding the callable you are providing for some reason. Bind KeyPress to your own function instead.

einarf commented 3 years ago

Also it might be better to self.destroy(), Using sys.exit() is not good practice.

einarf commented 3 years ago

oh. wait. Are you trying to register the events on the frame itself or using the tk root?

ShaunKulesa commented 3 years ago

To the frame. I did "<a>", function and that never worked.