【发布时间】:2018-11-25 15:29:26
【问题描述】:
一个没有类的简单例子:
from tkinter import *
master = Tk()
# Create this method before you create the entry
def return_entry(en):
"""Gets and prints the content of the entry"""
content = entry.get()
print(content)
Label(master, text="Input: ").grid(row=0, sticky=W)
entry = Entry(master)
entry.grid(row=0, column=1)
# Connect the entry with the return button
entry.bind('<Return>', return_entry)
mainloop()
以上是这个问题的答案:Why is Tkinter Entry's get function returning nothing?
所以我检查了代码并且它工作正常。但是 - 我不明白为什么“return_entry”括号中有一个“en”。代码的任何其他部分都没有提到它,所以我认为它是语法——但是为了什么?
如果我没有看到 OP 的帐户已停用 2 年,我会在上述答案上发表评论
【问题讨论】:
-
bind必须期望给它的函数接受一个参数;在这种情况下,大概是Entry。或者你在问什么是函数参数? -
大概是打错了;参数名为
en,但代码引用entry。 “我认为是语法” - 你是什么意思? -
看起来没有任何作用。我同意@jonsharpe 这很可能是一个错字
-
啊。谢谢。我对函数参数有一个粗略的概念,例如调用这样的函数: A_function(y=1) A_function(y) 但我从来不知道它可以以这种方式使用
-
@jonrsharpe 我的意思是 Carcigenicate 所说的。好吧-随时将您的 cmets 放入答案中,让我关闭此