类型错误:'>''method' 和 'int' 的实例之间不支持,但在这种情况下,'method' 是一个数字 [英] TypeError: '>' not supported between instances of 'method' and 'int', but in this case the 'method' is a number

查看:45
本文介绍了类型错误:'>''method' 和 'int' 的实例之间不支持,但在这种情况下,'method' 是一个数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始使用 python 创建视频游戏,但出现此错误:

I'm new to creating videogames with python and I got this error:

Traceback (most recent call last):
  File "/home/barbieri/pong.py", line 75, in <module>
    ball.setx(ball.xcor() + ball.dx) # make the ball move (xcor = current cordinate)
  File "/usr/lib/python3.7/turtle.py", line 1808, in setx
    self._goto(Vec2D(x, self._position[1]))
  File "/usr/lib/python3.7/turtle.py", line 3158, in _goto
    screen._pointlist(self.currentLineItem),
  File "/usr/lib/python3.7/turtle.py", line 755, in _pointlist
    cl = self.cv.coords(item)
  File "<string>", line 1, in coords
  File "/usr/lib/python3.7/tkinter/__init__.py", line 2469, in coords
    self.tk.call((self._w, 'coords') + args))]
_tkinter.TclError: invalid command name ".!canvas"

对于这些代码行:

while True:
    wn.update()  
    
    # Move the ball
    ball.setx(ball.xcor() + ball.dx) 
    ball.sety(ball.ycor() + ball.dy)

    # Borders
    if ball.ycor() > 290:
        ball.sety(290)
        ball.dy *= -1

有人可以帮我吗?Python 版本:python 3.7.3.Linux 操作系统.

Can somebody help me? Python version: python 3.7.3. Linux operating system.

我正在学习使用 python 3.6 的教程,这可能是原因还是相同?

I am following a tutorial that uses python 3.6, that could be the cause or it's the same?

推荐答案

你确定你的代码是这样的

Are you sure your code looks like this

if ball.ycor() > 290:

而不是这样

if ball.ycor > 290:

因为如果 ycor 是这样定义的

because if ycor is defined like this

class ball():

    def ycor(self):
        ...

然后你尝试像这样访问它

and you try to access it like this

if ball.ycor > 290:

然后你会得到这个错误

'>' not supported between instances of 'method' and 'int'

这篇关于类型错误:'&gt;''method' 和 'int' 的实例之间不支持,但在这种情况下,'method' 是一个数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆