编号51

func3(event)里的event是什么,去掉了就不行


提问于2019-08-05 01:54    245 已解决
from tkinter import *
root=Tk()
root.geometry("200x200")
text=Text(root)
text.pack()

def func3(event):
print("你按下了回车!")
text.bind("<Return>",func3)

root.mainloop()

站长回答


通过看源码可以知道:

    def _bind(self, what, sequence, func, add, needcleanup=1):
        """Internal function."""
        if isinstance(func, str):
            self.tk.call(what + (sequence, func))
        elif func:
            funcid = self._register(func, self._substitute,
                        needcleanup)
            cmd = ('%sif {"[%s %s]" == "break"} break\n'
                   %
                   (add and '+' or '',
                funcid, self._subst_format_str))
            self.tk.call(what + (sequence, cmd))
            return funcid
        elif sequence:
            return self.tk.call(what + (sequence,))
        else:
            return self.tk.splitlist(self.tk.call(what))
用来接受必须传的参数,不能去掉