1

Running the code below works perfectly on a windows computer. However, when I run it on my MacBook the Key-Release event, canvas.bind_all('<KeyRelease-w>', func), returns when w is pressed, not released.

Question: Is there a fixe/workaround inside tkinter or other libraries that comes as standard? I would like to avoid downloading new libraries as pygame or keyboard because I am not allowed to do that on my school computer.

*window (win 10) has python 3.5.2, Mac (Catalina 10.15.6) has python 3.8.5

from tkinter import*

tk = Tk()
canvas = Canvas(tk, width = 100, height = 100)
canvas.pack()

def func(event):
    print('Hello')

while True:
    canvas.bind_all('<KeyRelease-w>', func)
    tk.update()

Edit: According to the comments this is probably a bugg in the Tkinter library. However the question about possible workarounds is still unsolved.

Viktor Skarve
  • 129
  • 1
  • 8
  • This works fine on my python 3.7.4 win 10. Also did if you press and hold w you will notice that nothing happens, you press and leave, then it prints it on, right? – Delrius Euphoria Sep 17 '20 at 17:01
  • That's the thing, it works on windows not on Mac. When I press w on windows nothing happens until I release the button, as it should. On Mac 'hello' instantly poops up when I press w before I even have a chance to release – Viktor Skarve Sep 17 '20 at 17:08
  • Similar issue [here](http://python.6.x6.nabble.com/KeyPress-KeyRelease-binding-PCs-v-MacOS-td1975343.html) but no solutions i think, maybe a bug – Delrius Euphoria Sep 17 '20 at 17:12
  • Do you think we can expect a fix? – Viktor Skarve Sep 17 '20 at 17:39
  • Interesting. I see different behavior for different keys. Holding the "l" key (lowercase L) gives me a steady stream of press/release events. Holding the "w" does not. Even without any custom bindings I see different behavior among different keys. I would expect the steady stream of press/release events, but it's odd that sometimes there is a single, immediate press and release combination. – Bryan Oakley Sep 17 '20 at 17:43
  • I don't think it's a similar issue. _some_ keys do the press/release in a rapid cycle. This question seems to be about how the "w" gives a single press/release. – Bryan Oakley Sep 17 '20 at 17:45
  • FWIW, it's pointless to call `canvas.bind_all` in a loop. You only have to add the binding once. – Bryan Oakley Sep 17 '20 at 17:46
  • I dont maybe, just close it as a bug i guess. – Delrius Euphoria Sep 17 '20 at 17:59
  • Does anyone know a workaround to this problem inside Tkinter? – Viktor Skarve Sep 18 '20 at 07:39

0 Answers0