using input() to control python turtles - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: using input() to control python turtles (/thread-23639.html) |
using input() to control python turtles - amh80 - Jan-09-2020 I wrote the code below to try to get the turtle below to move the amount input, but I cannot seem to figure out why defining c will not work. How can I get the input to work? I keep getting an error message "ExternalError: TypeError: Cannot read property 'instance' of undefined on line 13." Line 13 is turtle.forward(int©). import turtle myTurtle = turtle.Turtle() myTurtle.forward(100) myTurtle.right(90) myTurtle.penup() myTurtle.forward(100) myTurtle.right(90) myTurtle.pendown() myTurtle.pencolor("green") myTurtle.right(90) myTurtle.forward(100) c=input(int()) turtle.forward(int(c)) myTurtle.back(100) RE: using input() to control python turtles - iMuny - Jan-09-2020 try c = input()input takes a string argument which is the prompt. RE: using input() to control python turtles - joe_momma - Jan-09-2020 turtle has a built in popup to add text and integers found here: turtle docs an example is: from turtle import * ta= getscreen() forward(100) right(90) penup() forward(100) right(90) pendown() pencolor("green") right(90) forward(100) fwd= numinput('forward Movement','Enter integer', default=1,minval=1,maxval=100) forward(fwd) right(100) RE: using input() to control python turtles - amh80 - Jan-10-2020 (Jan-09-2020, 09:30 PM)joe_momma Wrote: turtle has a built in popup to add text and integers found here: turtle docs an example is:from turtle import * ta= getscreen() forward(100) right(90) penup() forward(100) right(90) pendown() pencolor("green") right(90) forward(100) fwd= numinput('forward Movement','Enter integer', default=1,minval=1,maxval=100) forward(fwd) right(100) Hmmm...this still isn't working. I think it is because I am using Pycharm. The input() function in general is not working. However, I will now look for similar help sites specific to turtles RE: using input() to control python turtles - joe_momma - Jan-11-2020 I was able to run it from thonny, MU, idle, and from command line sorry not using pycharm you could try a different import: from turtle import getscreen,forward,right,penup,numinput,fd,pencolor,pendownor try: from turtle import Turtle, TurtleScreen myTurtle = Turtle() myTurtle.forward(100) myTurtle.right(90) myTurtle.penup() myTurtle.forward(100) myTurtle.right(90) myTurtle.pendown() myTurtle.pencolor("green") myTurtle.right(90) myTurtle.forward(100) fwd= TurtleScreen.numinput(myTurtle,'forward','Enter integer', default=1,minval=1,maxval=100) myTurtle.forward(fwd) myTurtle.back(100) |