当“返回键发布”事件发生时,我试图从Entry Box获取值。但它似乎不起作用。
我的代码类似于:
EntryBox = Text(base, bg="white",width="29", height="5", font="Arial")
EntryBox.bind("<KeyRelease-Return>", sendData(EntryBox.get(1.0, END)))我的sendData函数是:
def sendData(param):
if len(param) > 1:
EntryBox.delete(1.0, END)
insertText(param)
s.sendall(str.encode(param))
data = s.recv(4096)
insertText(data.decode('utf-8'))My insertText函数:
def insertText(param):
ChatLog.config(state = NORMAL)
ChatLog.insert(END, param)
ChatLog.config(state = DISABLED)发布于 2017-04-10 00:56:34
绑定参数必须是函数,而不是函数的结果。通过将()添加到函数的末尾,它将立即执行,并提供结果来绑定。您需要创建一个函数并提供:
EntryBox = Text(base, bg="white",width="29", height="5", font="Arial")
def on_return(event):
sendData(EntryBox.get(1.0, END))
EntryBox.bind("<KeyRelease-Return>", on_return)对于这么小的函数,如果需要,可以使用lambda创建它:
EntryBox = Text(base, bg="white",width="29", height="5", font="Arial")
EntryBox.bind("<KeyRelease-Return>", lambda event: sendData(EntryBox.get(1.0, END)))https://stackoverflow.com/questions/43313517
复制相似问题