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.

I am pasting his code and the syntax error. Any assistance would be
appreciated:

from tkinter import *

>>> import random
>>> import time
>>> tk = Tk()
>>> tk.title("Game")
''
>>> tk.resizable(0, 0)
''
>>> tk.wm_attributes("-topmost", 1)
''
>>> canvas = Canvas(tk, width=1400, height=835, bd=0, highlightthickness=0)
>>> canvas.pack()
>>> tk.update()
>>> class dot:
    def __init__(self, canvas, color):
        self.canvas = canvas
        canvas.create_oval(10, 10, 25, 25, fill='Blue', tags='dot1')


>>> this = dot(canvas, 'blue')
>>> print canvas.coords('dot1')
SyntaxError: invalid syntax
>>> print canvas.coords('dot1', x, y)
SyntaxError: invalid syntax
>>> print Canvas.coords('dot1', x, y)
SyntaxError: invalid syntax
>>> print canvas.coords('dot1', x, y)
SyntaxError: invalid syntax
>>> def ball(n, x, y):
    canvas.move(n, x, y)


>>> print coords('dot1', x, y)
SyntaxError: invalid syntax
>>> print canvas.coords('dot1', x, y)
SyntaxError: invalid syntax
>>> Canvas(master=None)
<tkinter.Canvas object .4389705880>
>>> print canvas.coords('dot1', x, y)
SyntaxError: invalid syntax
>>> print canvas.coords('dot1')
SyntaxError: invalid syntax
>>>
================ 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
>>>
================ RESTART: /Users/BScherer/Desktop/MazeTest.py
================
>>>
================ RESTART: /Users/BScherer/Desktop/MazeTest.py
================
Traceback (most recent call last):
  File "/Users/BScherer/Desktop/MazeTest.py", line 17, 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
>>>
================ RESTART: /Users/BScherer/Desktop/MazeTest.py
================
>>>
================ RESTART: /Users/BScherer/Desktop/MazeTest.py
================
Traceback (most recent call last):
  File "/Users/BScherer/Desktop/MazeTest.py", line 17, 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
>>>
================ RESTART: /Users/BScherer/Desktop/MazeTest.py
================
Traceback (most recent call last):
  File "/Users/BScherer/Desktop/MazeTest.py", line 17, in <module>
    restart()
  File "/Users/BScherer/Desktop/MazeTest.py", line 14, in restart
    if canvas.coords('dot1', x, y) == ('dot1', x >= 300, y>= 300):
NameError: name 'x' is not defined
>>>
================ RESTART: /Users/BScherer/Desktop/MazeTest.py
================
Traceback (most recent call last):
  File "/Users/BScherer/Desktop/MazeTest.py", line 17, in <module>
    restart()
  File "/Users/BScherer/Desktop/MazeTest.py", line 14, in restart
    while canvas.coords('dot1', x, y) == ('dot1', x >= 300, y>= 300):
NameError: name 'x' is not defined
>>>
================ RESTART: /Users/BScherer/Desktop/MazeTest.py
================
Traceback (most recent call last):
  File "/Users/BScherer/Desktop/MazeTest.py", line 17, in <module>
    restart(x, y)
NameError: name 'x' is not defined
>>>
================ RESTART: /Users/BScherer/Desktop/MazeTest.py
================
>>>
================ RESTART: /Users/BScherer/Desktop/MazeTest.py
================
>>>
================ RESTART: /Users/BScherer/Desktop/MazeTest.py
================
Traceback (most recent call last):
  File "/Users/BScherer/Desktop/MazeTest.py", line 21, in <module>
    restart2()
  File "/Users/BScherer/Desktop/MazeTest.py", line 18, in restart2
    if restart(x, y) == restart(x > 500, y > 500):
NameError: name 'x' is not defined
>>>

Thanks for any help you can give!

-- 
Lisa Waters, PhD
Technology Integration
Flint Hill School
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to