-1
Good afternoon guys, I have the following code that actually works perfectly. However I have an error when I click on "bt1" (boot button) my program crashes. However, it is working on the console. Only the executable locks. Help me find a solution to this ? and it would be possible for me to create a function just to enable or disable the Listener ? Thank you
Edit: Well, I found that if I put Listener.Join() before mainloop(), It works, prints all keys on the console, but Tk window does not open. But if I put the mainloop() before, the jenala opens, but does not print any key..
from pynput.keyboard import Listener
from tkinter import *
from functools import partial
def press(key):
keyd = str(key)
keyd = keyd.replace("'","")
if (keyd == "Key.space" or keyd== "Key.shift_r" or keyd=="Key.ctrl_l" or
keyd=="Key.caps_lock" or keyd == "Key.right" or keyd == "Key.left"
or keyd == "Key.right" or keyd == "Key.ctrl_r" or keyd== 'Key.backspace'
or keyd == 'Key.shift' or keyd == 'Key.tab' or keyd == 'Key.cmd'):
keyd = ""
with open('KeyTester.docx', "a") as op:
op.write(keyd + "\n")
print(keyd)
def ena():
with Listener(on_press=press) as l:
l.join()
def dis():
with Listener(on_press=press) as l:
l.stop()
window = Tk()
bt1 = Button(window, text="Iniciar Atividade", command=ena).grid()
bt2 = Button(window, text="Parar Atividade", command=dis).grid()
btRel = Button(window, text="Verificar Relatório").grid()</code>
window.title('KeyBLG 1.0')
window.geometry("300x200+1200+400")
window.mainloop()
I did what you said, the error remains the same, when I click start the program hangs, but on the console it prints the keys I press. I figured out why this is happening but I don’t know how to fix it. In my view, it appears when I start Listener with Listener.Join() , window.mainloop() cannot be active. , because if I put Listener.Join() before the window.mainloop() it works, but the Tkinter window does not appear. , and if I put Listener.Join() after mainloop(), the window opens, but Listener does not record anything.
– Luan Gabriel
in the ena() and dis() functions was in Mbar to be on_press=press?
– pydoni
It doesn’t change anything, if I put the Listener.Join() before the mainloop(), it works, it prints all keys on the console, but the Tk window doesn’t open. But if I put the mainloop() before, the jenala opens, but does not print any key..
– Luan Gabriel
what the intention of the programme is?
– pydoni
use . bind from Tkinter ñ server?
– Elton Nunes