I am writing a python hangman code with tkinter interactive window, which includes a keyboard. I have created the keyboard, however I cannot figure out how to find out which keyboard key was pressed by the user and how to store it as a letter in a variable. I will be really grateful for any help!
klavesnice = Tk()
klavesnice.geometry("800x700+120+100")
buttons = []
buttons = [
'q','w','e','r','t','y','u','i','o','p',
'a','s','d','f','g','h','j','k','l',
'z','x','c','v','b','n','m'
]
radek=3 #row
sloupec=0 #column
for button in buttons:
command=lambda x=button: select(x)
if button!='Space':
Button(klavesnice,text=button,width=5,font=("arial",14,"bold"),bg='powder blue',command=command,padx=3.5,pady=3.5,bd=5).grid(row=radek,column=sloupec)
if button=='Space':
Button(klavesnice,text=button,command=command).grid(row=5,column=sloupec)
sloupec+=1
#určení rozložení klávesnice
if sloupec>9 and radek==3:
sloupec=0
radek+=1
if sloupec>8 and radek==4:
sloupec=0
radek+=1
The code above is what displays the keyboard and the code below is the only thing I was able to come up with, which does not save the clicked key to a variable.
zadane=""
entry=Text(zadane_rm,width=43,height=3)
entry.grid(row=1,columnspan=40)
def select(value):
if value=='Space':
entry.insert(END,'')
else:
entry.insert(END, value)
I would like to store the clicked letter in a string variable called zadane
.