Please Help name 'spinBox' is not defined THIS SHOULD WORK! RIGHT???

43 views
Skip to first unread message

Jarrell Easley

unread,
Feb 10, 2017, 5:41:29 AM2/10/17
to VPython-users
from visual import *

def spinBox():
    myBox = box(color = (1.0, 0.0, 0.0))
    while True:
        # Slow down the animation to 60 frames per second.
        # Change the value to see the effect!
        rate(60)
        myBox.rotate(angle=pi/100)

Why does VIDLE gives me the error?

Traceback (most recent call last):
  File "<pyshell#1>", line 1
    spinBox()
NameError: name 'spinBox' is not defined

Bruce Sherwood

unread,
Feb 10, 2017, 7:49:58 AM2/10/17
to VPython-users
In VIDLE, using Classic VPython, your program works for me as shown below, which includes the addition of "spinBox()" to your program. I run the program by pressing F5 in the VIDLE editor.

Exactly how do you run your program? The error message implies that you run a one-line program "spinBox()" in a file named "pyshell#1" rather than running the program itself. For that to work you would have to import your program into pyshell#1, otherwise Python will indeed give the error message you see.

from visual import *

def spinBox():
    myBox = box(color = (1.0, 0.0, 0.0))
    while True:
        # Slow down the animation to 60 frames per second.
        # Change the value to see the effect!
        rate(60)
        myBox.rotate(angle=pi/100)

spinBox()

Jarrell Easley

unread,
Feb 10, 2017, 9:48:35 PM2/10/17
to VPython-users
Wow thanks you resolved my issue, which was that I was running the function from the VIDLE editor but without calling the function within the module itself. Once I add 'spinBox()' to call the method at the end of the module and run it (F5) the program is interpreted and VPython show the rotating box. Thank you.
Reply all
Reply to author
Forward
0 new messages