I am trying to make a entrybox that gets keyboard input when it is focused, and show only that key name in the middle of the box with no blinking bar and not allowing editing. And also changes a variable to the key.
So if [ ]
is a entrybox. I type F7
then the box should show [ F7 ]
, then when I press the backspace button the box should show [ Backspace ]
.
In my code special keys likeF1
, F2
, ect are not even giving me the right feedback by giving me back ''
for all function key and '\x08'
for the backspace key. If all the keys showed different characters I think I could find a way to link the characters and the names I want to print. But this is not the case. And the entrybox types like this [1234| ]
not like [ 1 ]
. And I have no idea how to get the key names in the entrybox.
def callback(event):
key_input_entered.focus_set()
print(repr(event.char))
kb_frame = ttk.Frame(self.kb)
kb_frame.grid(column=0, row=1, pady=(7, 19))
ttk.Label(kb_frame, text='Enter Key').grid(column=0, row=0, pady=4)
key_input = tk.StringVar()
key_input_entered = ttk.Entry(kb_frame, width=15, textvariable=key_input)
key_input_entered.grid(column=0, row=1)
key_input_entered.bind('<Key>', callback)