python - onscreenclick 在乌龟,python 中不起作用
问题描述
我想使用turtle python在屏幕上按下一个按钮。这并不难,但我尝试使用类来完成它并没有用:
class Window:
def __init__(self):
self.name = 'test'
def deletewindow(self, x, y):
if x < 10 and x > 0 and y < 10 and y > 0:
del self
wn.listen()
wn.onscreenclick(deletewindow, 1)
我得到这个错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3.8/tkinter/__init__.py", line 1883, in __call__
return self.func(*args)
File "/usr/lib/python3.8/turtle.py", line 675, in eventfun
fun(x, y)
TypeError: deletewindow() missing 1 required positional argument: 'y'
解决方案
问题是该deletewindow
函数需要一个名为 self 的参数,通常会给出该参数,但您输入deletewindow
not Window.deletewindow
。
你应该做
wn.onscreenclick(Window.deletewindow, 1)
推荐阅读
- javascript - chrome.runtime.onmessage.addlistener 收不到消息
- ios - 为什么应用在后台和前台接收时,在 IOS 上收不到 FCM 通知?扑
- elasticsearch - 使用 Kubernetes 的 elasticsearch 数据丢失 - 索引被自动删除和创建
- sql - 知道 SQL Server 中所有数据库表之间的关系类型吗?
- python - WebElement 类型的 Selenium 对象没有 len()
- json - 无法将指标发送到 Splunk HEC
- jenkins - 找出在特定从属或代理中运行的作业
- html - Animate.css 在我的 Vue 3 项目中没有动画
- microsoft-teams - Microsoft Bot Framework REST API - 将包含附件的消息发送到对话后无法检索活动 ID
- arrays - 如何在 MATLAB 中获得二维矩阵列表的所有成对相关性?