[Tutor] Revised question-Make an object disappear

Steven D'Aprano steve at pearwood.info
Tue Apr 26 11:22:15 EDT 2016


On Tue, Apr 26, 2016 at 10:55:24AM -0400, Lisa Hasler Waters wrote:
> Dear Tutors,
> 
> I have a student who is creating a game in TKinter. He wants the ball
> (object) to disappear when it hits when it hits the wall. He continues to
> get a syntax error message when trying to print the coordinates (he was
> printing the coordinates because he wanted to use its output to use again
> as inputs). He also wants to define the x-coordinates.
> 
> He's running OSX 10.5, Python 3.5.1.

Python 3 no longer treats print as a special statement. It is now an 
ordinary function, like len(), so you need parentheses (round brackets).

> >>> print canvas.coords('dot1')
> SyntaxError: invalid syntax

Change that to 

print(canvas.coords('dot1'))

and it should work.



> ================ RESTART: /Users/BScherer/Desktop/MazeTest.py
> ================
> Traceback (most recent call last):
>   File "/Users/BScherer/Desktop/MazeTest.py", line 16, in <module>
>     restart()
>   File "/Users/BScherer/Desktop/MazeTest.py", line 14, in restart
>     if canvas.coords('dot1', x >= 500, y >= 500):
> NameError: name 'x' is not defined

It is hard to say what is happening here. The error is clear: the name 
"x" is not defined, but I'm not sure why it is not defined (apart from 
the obvious "the student hasn't defined it yet") or where it needs to be 
defined in order to work in the restart() function.



-- 
Steve


More information about the Tutor mailing list