I borrowed some code from another thread I found on this website, but when I tried to form a program around it, I found that it can only be used once. Repeated code doesn't work.
import tkinter as tk
def keyDetect(event):
root.destroy()
if event.char == event.keysym:
print(event.char)
elif len(event.char) == 1:
print(event.keysym, event.char)
else:
print(event.keysym)
root = tk.Tk()
root.bind_all('<Key>', keyDetect)
root.withdraw()
root.mainloop()
print('1')
root = tk.Tk()
root.bind_all('<Key>', keyDetect)
print('2')
root.withdraw()
print('3')
root.mainloop()
print('4')
Using the 4 prints above shows where the problem is, "3"
is printed but "4"
isn't.