2017-12-07 3 views
0

항목을 지우고 clear (clearTextBox())하고 newQuote()를 실행하려고합니다. 두 번째 바인딩을 추가 했으므로 삭제되지 않습니다. 어떤 아이디어?엔트리 위젯이 함수에서 지워지지 않을 것입니다.

from random import * 
from tkinter import * 

def clearTextBox(event): 
    textBox.delete(0, END) 
    textBox.insert(0, "") 

def newQuote(event): 
    rightLabel.config(text=quotes[randint(0,10)]) 

textBox = Entry(leftFrame, width=60) 
textBox.pack(ipady=10, side=LEFT) 
textBox.bind("<Return>", clearTextBox) 
textBox.bind("<Return>", newQuote) 

root.mainloop() 

답변

1

두 번째로 bind을 호출하면 첫 번째를 덮어 씁니다.

이 문제를 해결하려면, 당신은 두 함수를 호출하는 키워드 인수 add="+"를 추가 할 수 있습니다

textBox.bind("<Return>", newQuote, add="+") 
+0

덕분에 빠른 도움이 완벽하게 작동! 8 분 안에 진드기를 맞히고, 너무 빠르다. –

+0

콜백 함수를 하나만 사용하여 여러 함수를 호출하는 경우에도 [이 대답] (https://stackoverflow.com/a/5839549/7032856)을 볼 수 있습니다. . – Nae

관련 문제