Python 海龟库“onclick”的问题功能
所以,问题是“onclick”功能不起作用。相反,它只是在代码启动时打印测试代码(print('working'))。请帮忙!
SubmitButton = turtle.Turtle()
SubmitButton.penup()
SubmitButton.goto(0,-300)
SubmitButton.shape('square')
SubmitButton.shapesize(2)
SubmitButton.fillcolor('red')
SubmitButton.penup()
SubmitButton.goto
SubmitButton.onclick(print("working"))
有代码片段,让我知道您是否需要更多。
So, the problem is is that the "onclick" function is not working. It is instead just printing the test code (print('working')) when the code is started. Please help!
SubmitButton = turtle.Turtle()
SubmitButton.penup()
SubmitButton.goto(0,-300)
SubmitButton.shape('square')
SubmitButton.shapesize(2)
SubmitButton.fillcolor('red')
SubmitButton.penup()
SubmitButton.goto
SubmitButton.onclick(print("working"))
There is the snippet of the code, lemme know if you need anymore.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
onclick
需要传递一个函数,它将调用该函数。该函数需要有两个参数。 (请参阅文档,您应该始终使用它在此处发帖之前先查阅一下)。您向其传递print()
的返回值,即None
。您可以使用lambda
,它创建一个函数,在调用该函数时将调用print()
:或者您可以定义一个函数并将其传入:
请注意如何我传入
onclick_function
但不调用该函数。onclick
needs to be passed a function, which it will call. The function needs to have two arguments. (See the Documentation, which you should always look up before posting here). You're passing it the returned value of aprint()
, which isNone
. You could use alambda
, which creates a function that will callprint()
when that function is called:Or you could define a function and pass that in:
Notice though how I'm passing in
onclick_function
but not calling that function.