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

43 vues
Accéder directement au premier message non lu

Jarrell Easley

non lue,
10 févr. 2017, 05:41:2910/02/2017
à 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

non lue,
10 févr. 2017, 07:49:5810/02/2017
à 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

non lue,
10 févr. 2017, 21:48:3510/02/2017
à 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.
Répondre à tous
Répondre à l'auteur
Transférer
0 nouveau message