Python Forum
using input() to control python turtles
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
using input() to control python turtles
#1
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)
Reply
#2
try

c = input()
input takes a string argument which is the prompt.
Reply
#3
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)
Reply
#4
(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
Reply
#5
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,pendown
or 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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  db migration(db version control) for python lubaz 2 2,699 May-30-2021, 01:36 PM
Last Post: lubaz
  python 3 raspberry pi 4 dual control motor programming problem yome 0 1,938 Mar-21-2021, 05:17 PM
Last Post: yome
  Use of input function to change screen background color in Turtles Oldman45 3 4,739 Jul-10-2020, 09:54 AM
Last Post: Oldman45
  control a linux program with python Fifoux082 9 4,006 May-08-2020, 04:24 PM
Last Post: Fifoux082
  Python 3+ kybd and mouse control keycodes ineuw 5 2,838 Aug-20-2019, 07:51 AM
Last Post: ineuw
  Windows Volume Control using python Arun 1 4,688 May-17-2019, 02:50 PM
Last Post: Larz60+
  Remote control of the Visual Studio 2013 debug menu using Python MariusTo 0 2,450 Jan-17-2018, 04:58 PM
Last Post: MariusTo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020