Mon code:Binding une fonction à une touche ne fonctionne pas
import tkinter
master = tkinter.Tk()
master.title("test1")
master.geometry("300x300")
masterFrame = tkinter.Frame(master)
masterFrame.pack(fill=tkinter.X)
checkboxArea = tkinter.Frame(masterFrame, height=26)
checkboxArea.pack(fill=tkinter.X)
inputStuff = tkinter.Frame(masterFrame)
checkboxList = []
def drawCheckbox():
checkboxList.append(entry.get())
entry.delete(0,tkinter.END)
checkboxRow = tkinter.Frame(checkboxArea)
checkboxRow.pack(fill=tkinter.X)
checkbox1 = tkinter.Checkbutton(checkboxRow, text = checkboxList[-1])
checkbox1.pack(side=tkinter.LEFT)
deleteItem = tkinter.Button(checkboxRow, text = "x", command=checkboxRow.destroy, bg="red", fg="white", activebackground="white", activeforeground="red")
deleteItem.pack(side=tkinter.RIGHT)
def bindToEnter():
master.bind('<Return>', drawCheckbox)
def createInputStuff():
paddingFrame = tkinter.Frame(inputStuff, height=5)
paddingFrame.pack(fill=tkinter.X)
buttonDone.pack()
inputStuff.pack()
buttonAdd.pack_forget()
bindToEnter()
def removeInputStuff():
inputStuff.pack_forget()
buttonAdd.pack()
buttonDone.remove()
buttonDone = tkinter.Button(inputStuff, text = "Close Input", command=removeInputStuff)
buttonAdd = tkinter.Button(masterFrame, text="Add Item", command=createInputStuff)
buttonAdd.pack()
topInput = tkinter.Frame(inputStuff)
bottomInput = tkinter.Frame(inputStuff)
topInput.pack()
bottomInput.pack()
prompt = tkinter.Label(topInput, text="What do you want your checkbox to be for?")
prompt.pack()
entry = tkinter.Entry(bottomInput, bd=3)
entry.pack(side=tkinter.LEFT)
buttonConfirm = tkinter.Button(bottomInput, text="Confirm", command=drawCheckbox)
buttonConfirm.pack(side=tkinter.LEFT)
master.mainloop()
L'idée est d'avoir appuyer sur Retour/Entrée faire la même chose que de frapper le bouton « Confirmer », en cours d'exécution drawCheckbox. Ceci est toujours un travail en cours, je vais dissocier la fonction drawCheckbox de la touche Entrée lorsque removeInputStuff est exécuté. Néanmoins, je ne comprends toujours pas pourquoi l'appui sur la touche Entrée n'exécute pas la fonction à laquelle elle est liée.