|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
我想达到的效果是:
按下 回车键 触发函数。
但是下面这段代码,按下回车键会报错,
直接用鼠标点击 BUTTON 却一切正常,没有报错。
然后我将BUTTON 绑定回车,也会报错
button.bind('<Button-1>', msg_demand)
command 调用函数正常,键盘调用却不行,请问为什么?
感谢感谢。
报错:————————————————————
return self.func(*args)
TypeError: msg() takes 0 positional arguments but 1 was given
————————————————————————————————
原代码:
from tkinter import *
def msg_demand():
print(entry.get())
root = Tk()
root.bind("<Return>",msg_demand)
button_search = Button(root, text=' O K ',command=msg_demand)
button_search.grid(padx=5,pady=3)
entry = Entry(root)
entry.grid()
entry.focus_set()
root.mainloop()
绑定按钮需要重新定义个函数,用于enter触发
def msg_demand_enter(self):msg_demand()
|
|