Hey Christian, the sole purpose of me coming here was to figure out how to move turtles using the arrow keys in 3.4! XD, and I realised that this is in an older version. If you could, it would be awesome for you to reply to this comment with a brief explanation and an example of how to move turtles with arrow keys. Regards
Awesome Vid! I created a fourth function for the turtles navigation. ------------------------ def decspeed(): global speed speed -= 1 ------------------------ player.onkey(decspeed, "Down") ------------------------ This code will slow down the turtle when you press the down arrow key.
Why is my turtle moving with the updated speed as I press the up arrow. In your case when you are pressing the up arrow only then the speed increases and gets back to the normal speed after releasing the up arrow. In my case even after releasing the up arrow my speed is set to the current increased speed. Why is this happening?
Hey, christian! Thanks for these awesome and helpful videos. So, i have a question: the code worked just fine up until the turning commands and so on. So what my turtle did was just moving forward as it was supposed to. But wehen i implemented the stuff with turning, my turtle just vanished. Don't waste to much time trying to answer this question but if you have an idea why this is happening i'd really appreciate an answer. Thank you
@@TokyoEdTech oh, i'm really sorry. So here's the pastebin link: pastebin.com/D0gVknNR And the error message: C:\Users\antho\AppData\Local\Programs\Python\Python37-32\python.exe C:/Users/antho/PycharmProjects/untitled5/random.py Traceback (most recent call last): File "C:/Users/antho/PycharmProjects/untitled5/random.py", line 3, in import random File "C:\Users\antho\PycharmProjects\untitled5 andom.py", line 36, in player.forward(speed) File "C:\Users\antho\AppData\Local\Programs\Python\Python37-32\lib\turtle.py", line 1637, in forward self._go(distance) File "C:\Users\antho\AppData\Local\Programs\Python\Python37-32\lib\turtle.py", line 1605, in _go self._goto(ende) File "C:\Users\antho\AppData\Local\Programs\Python\Python37-32\lib\turtle.py", line 3158, in _goto screen._pointlist(self.currentLineItem), File "C:\Users\antho\AppData\Local\Programs\Python\Python37-32\lib\turtle.py", line 755, in _pointlist cl = self.cv.coords(item) File "", line 1, in coords File "C:\Users\antho\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 2466, in coords self.tk.call((self._w, 'coords') + args))] _tkinter.TclError: invalid command name ".!canvas" Process finished with exit code 1C:\Users\antho\AppData\Local\Programs\Python\Python37-32\python.exe C:/Users/antho/PycharmProjects/untitled5/random.py Traceback (most recent call last): File "C:/Users/antho/PycharmProjects/untitled5/random.py", line 3, in import random File "C:\Users\antho\PycharmProjects\untitled5 andom.py", line 36, in player.forward(speed) File "C:\Users\antho\AppData\Local\Programs\Python\Python37-32\lib\turtle.py", line 1637, in forward self._go(distance) File "C:\Users\antho\AppData\Local\Programs\Python\Python37-32\lib\turtle.py", line 1605, in _go self._goto(ende) File "C:\Users\antho\AppData\Local\Programs\Python\Python37-32\lib\turtle.py", line 3158, in _goto screen._pointlist(self.currentLineItem), File "C:\Users\antho\AppData\Local\Programs\Python\Python37-32\lib\turtle.py", line 755, in _pointlist cl = self.cv.coords(item) File "", line 1, in coords File "C:\Users\antho\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 2466, in coords self.tk.call((self._w, 'coords') + args))] _tkinter.TclError: invalid command name ".!canvas" Process finished with exit code 1
great tutorials but i have question i am using python v3.6.0 and when i use onkey fuction it give me an error which says " 'Turtle' object has no attribute 'onkey' " can you please help me with that ? i want the turtle to turn right when i press right arrow thanks in advance
i literally used your exact code in testing but i will post it : import turtle wn = turtle.Screen() wn.bgcolor("black") snake = turtle.Turtle() snake.color("blue") snake.shape('square') snake.penup() snake.speed(0) def turnleft(): snake.left(90) def turnright(): snake.right(90) snake.listen() snake.onkey(turnleft,"Left") speed = 1 delay = input("press enter to finish")
@@rosam5949 Actually, My fail was here: I have wroted the turtle name that I want to control: p.listen() But instead I need to write "turtle" (Not the name of the turtle): turtle.listen() Then, I should write onkeypress() command: (New onkey() command form): turtle.onkeypress("put here your def",'Button') (The def must not have any "") (Button Left,Right,Down+any letter have to be with '(example)') In the def it must have to mention the turtle I want to control, Like this: def left(): p.left(90) Ive just needed to give more attention to the video, Thats all. Thanks for reading.
Hi, could you tell me why we use turtle.onkey(turnleft,"Left") instead of player.onkey((turnleft,"Left") ? On using player.onkey(turnleft,"Left") it shows the error - 'Turtle' object has no attribute 'onkey'
In C++ it's a really bad habit using global variables, such as speed in this case. We rather use classes with the variable as a private. Is global variables also bad in python?
I am having a problem with this code, for some reason my Python Interpreter does not recognize listen or onkey. Is there any suggestions about what I should do?
Thank you for responding, I fixed the problem, I was using Python 3.5 which still had the Turtle module but apparently deleted some of the contents such as listen and onkey. I downloaded Python 2.7 and now it is working perfectly, thank you!
So, I would have thought a simpler way of changing the turtle's orientation would be to call the player.left() method from within the onkey() method - rather than calling the function you defined as "turnleft". like so: turtle.onkey(player.left(30), "Left") However that doesn't work. Is that a design restriction of Python, not allowing recursive method use? Or maybe I'm just not getting something... :-)
@@TokyoEdTech The lambda trick worked, thanks for the tip! You are incredibly helpful with your videos and for you to respond to a comment like that is just above and beyond - well done!
Hello nice series do you know how to control the speed of 2 turtles. The turtles are both using the global one so of i press up both of their speed goes up one. Please help me with this
this is what i have done: #Turtle Graphics Game import turtle #set up screen wn = turtle.Screen() wn.bgcolor('lightgreen') #Create player turtle player = turtle.Turtle() player.color('blue') player.shape('triangle') player.penup() #Set speed variable speed = 1 #Define functions def turnrigth(): player.right(30) def turnleft(): player.left(30) #Set keyboard bindings turtle.listen() turtle.onkey(turnleft, "Left") turtle.onkey(turnright, "Right") while True: player.forward(speed) delay = raw_input('Press Enter to finish.') exact code as you.
The turnleft does not work. It tells me that is *invalid syntax (, line 24(turtle.onkey(turnleft "left")pylint (syntax-error)[24-1])*. Look at my good for a second please: import turtle #screen setup wn = turtle.Screen() wn.bgcolor('lightgreen') #create player turtle player = turtle.Turtle() player.color('blue') player.shape('triangle') player.penup() #set speed of player speed = 1 #define functions def turnleft(): player.left(30) #set keyboard stuff turtle.listen() turtle.onkey(turnleft "Left") #This line of code is giving me trouble! while True: player.forward(speed) delay = input("Press Enter To finish: ")
i have read all the comments and have googled countless things but it just does not move when i press a key import turtle t = turtle wn = turtle.Screen() wn.bgcolor("black") player1 = t.Turtle() player1.color("white") player1.shape("triangle") player1.penup() while True: player1.fd(1) def turnleft(): player1.left(30) t.onkey(turnleft, "left") t.listen() t.mainloop()
Traceback (most recent call last): File "C:/Users/HiHi/Documents/k.py", line 16, in turtle.onkeypress(turnleft, "left") NameError: name 'turnleft' is not defined my PROBLEM
I’m happy to take a look, but I need to see the actual code. Please share your code via pastebin.com link so I can download and test it. To learn how, please watch this video and then get back to me: th-cam.com/video/L6AwVuu6O3Y/w-d-xo.html Keep on codin’!
#Turtle Graphics Game import turtle #Set up screen wn = turtle.Screen() wn.bgcolor( "lightgreen" ) #Create player turtle player = turtle.Turtle() player.color("blue") player.shape("circle") player.penup() #Set speed variable speed = ("10") #Define functions def turnleft(): player.left(30) #set keyboard bindings turtle.listen() turtleonkey(turnleft, "Left") while True: player.foward(speed) delay = raw_input ("press Enter To Finish,") this is all of it so far :)
Traceback (most recent call last): File "C:/Users/Toshiba/Desktop/Goood.py", line 31, in turtle.onkey(turnleft,"left") File "", line 1, in onkey File "C:\Python33\lib\turtle.py", line 1386, in onkey self._onkeyrelease(fun, key) File "C:\Python33\lib\turtle.py", line 686, in _onkeyrelease self.cv.bind("" % key, eventfun) File "C:\Python33\lib\turtle.py", line 415, in bind self._canvas.bind(*args, **kwargs) File "C:\Python33\lib\tkinter\__init__.py", line 1039, in bind return self._bind(('bind', self._w), sequence, func, add) File "C:\Python33\lib\tkinter\__init__.py", line 994, in _bind self.tk.call(what + (sequence, cmd)) _tkinter.TclError: bad event type or keysym "left" THis is the error help please!
import turtle back = turtle.Screen() back.bgcolour ('Blue') what I tried The error: back.bgcolour ('Blue') AttributeError: '_Screen' object has no attribute 'bgcolour'
If player.listen() dosent work then try writing your screen variable name like mine is sc then i typed sc.listen() now there is no excuse for programm to not work i hope i fixed your program :D
Christian Thompson can you look up my comment on part 5 plz... I have some bad errors and i typed all correct (variable names are diffrent and that is all)
I don't understand this error raceback (most recent call last): File "/Users/Someone/Documents/Python Game L.py", line 32, in player.forward(speed) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/turtle.py", line 1638, in forward self._go(distance) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/turtle.py", line 1606, in _go self._goto(ende) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/turtle.py", line 3160, in _goto screen._pointlist(self.currentLineItem), File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/turtle.py", line 754, in _pointlist cl = self.cv.coords(item) File "", line 1, in coords File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/tkinter/__init__.py", line 2795, in coords self.tk.call((self._w, 'coords') + args))] _tkinter.TclError: invalid command name ".!canvas"
Hey Christian, the sole purpose of me coming here was to figure out how to move turtles using the arrow keys in 3.4! XD, and I realised that this is in an older version. If you could, it would be awesome for you to reply to this comment with a brief explanation and an example of how to move turtles with arrow keys.
Regards
same problem. did you get the solution?
I was very interested in making games of my own and you sir are the key to getting me on the right path! Do you have more tutorials?
Where do you find the commands to type in? Is there a cheat sheet?
Ex: Left, Right, Up, Down.
Awesome Vid! I created a fourth function for the turtles navigation.
------------------------
def decspeed():
global speed
speed -= 1
------------------------
player.onkey(decspeed, "Down")
------------------------
This code will slow down the turtle when you press the down arrow key.
+Blu Brackets Great idea! You can even get the turtle to go into reverse!
Thanks.
if your python project was crashing it might because you the did not setup the screen for some reason this fixes the problem hope this helps ;)
Thanks for the help!
Whenever I try to run the program, in IDLE, it shows that the program is not responding and in Spyder, nothing happens at all.
Hey can you help me out with creating a Square hunt game on Python and turtle. Its very tough assignment for me
Sorry - I don't really do requests.
Why is my turtle moving with the updated speed as I press the up arrow. In your case when you are pressing the up arrow only then the speed increases and gets back to the normal speed after releasing the up arrow. In my case even after releasing the up arrow my speed is set to the current increased speed. Why is this happening?
There is a link in the description labeled “NEED HELP?” Check that out and get back to me. Keep on codin’!
Hey, christian! Thanks for these awesome and helpful videos. So, i have a question: the code worked just fine up until the turning commands and so on. So what my turtle did was just moving forward as it was supposed to. But wehen i implemented the stuff with turning, my turtle just vanished. Don't waste to much time trying to answer this question but if you have an idea why this is happening i'd really appreciate an answer. Thank you
@@TokyoEdTech oh, i'm really sorry.
So here's the pastebin link:
pastebin.com/D0gVknNR
And the error message:
C:\Users\antho\AppData\Local\Programs\Python\Python37-32\python.exe C:/Users/antho/PycharmProjects/untitled5/random.py Traceback (most recent call last): File "C:/Users/antho/PycharmProjects/untitled5/random.py", line 3, in import random File "C:\Users\antho\PycharmProjects\untitled5
andom.py", line 36, in player.forward(speed) File "C:\Users\antho\AppData\Local\Programs\Python\Python37-32\lib\turtle.py", line 1637, in forward self._go(distance) File "C:\Users\antho\AppData\Local\Programs\Python\Python37-32\lib\turtle.py", line 1605, in _go self._goto(ende) File "C:\Users\antho\AppData\Local\Programs\Python\Python37-32\lib\turtle.py", line 3158, in _goto screen._pointlist(self.currentLineItem), File "C:\Users\antho\AppData\Local\Programs\Python\Python37-32\lib\turtle.py", line 755, in _pointlist cl = self.cv.coords(item) File "", line 1, in coords File "C:\Users\antho\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 2466, in coords self.tk.call((self._w, 'coords') + args))] _tkinter.TclError: invalid command name ".!canvas" Process finished with exit code 1C:\Users\antho\AppData\Local\Programs\Python\Python37-32\python.exe C:/Users/antho/PycharmProjects/untitled5/random.py Traceback (most recent call last): File "C:/Users/antho/PycharmProjects/untitled5/random.py", line 3, in import random File "C:\Users\antho\PycharmProjects\untitled5
andom.py", line 36, in player.forward(speed) File "C:\Users\antho\AppData\Local\Programs\Python\Python37-32\lib\turtle.py", line 1637, in forward self._go(distance) File "C:\Users\antho\AppData\Local\Programs\Python\Python37-32\lib\turtle.py", line 1605, in _go self._goto(ende) File "C:\Users\antho\AppData\Local\Programs\Python\Python37-32\lib\turtle.py", line 3158, in _goto screen._pointlist(self.currentLineItem), File "C:\Users\antho\AppData\Local\Programs\Python\Python37-32\lib\turtle.py", line 755, in _pointlist cl = self.cv.coords(item) File "", line 1, in coords File "C:\Users\antho\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 2466, in coords self.tk.call((self._w, 'coords') + args))] _tkinter.TclError: invalid command name ".!canvas" Process finished with exit code 1
What IDE do you use?
You're in luck - I have a video about this exact topic! th-cam.com/video/4bL-lCP2tec/w-d-xo.html
great tutorials but i have question i am using python v3.6.0 and when i use onkey fuction it give me an error which says " 'Turtle' object has no attribute 'onkey' " can you please help me with that ? i want the turtle to turn right when i press right arrow thanks in advance
i literally used your exact code in testing but i will post it :
import turtle
wn = turtle.Screen()
wn.bgcolor("black")
snake = turtle.Turtle()
snake.color("blue")
snake.shape('square')
snake.penup()
snake.speed(0)
def turnleft():
snake.left(90)
def turnright():
snake.right(90)
snake.listen()
snake.onkey(turnleft,"Left")
speed = 1
delay = input("press enter to finish")
Christian Thompson but I already did try that and still got me the same error I will try again and tell youu thanks for the help
Muhammad mohsen use wn.listen() and wn.onkey(fun, "key"). it works for me....
same
SkullMaster 1785 -Gaming And More Thanks.
what idle you use ?
Awesome video bro , thank u so much
Onkey() and Listen() does not work anymore. Why?
Please anyone who knows respond.
Oh sorry for the bothering!
I have already solved it.
Thank you so much for listening to my comment!
I really appreciate that.
Hello, I am having the same problem, how did you solve it?
@@rosam5949 Actually, My fail was here: I have wroted the turtle name that I want to control:
p.listen()
But instead I need to write "turtle"
(Not the name of the turtle):
turtle.listen()
Then, I should write onkeypress() command:
(New onkey() command form):
turtle.onkeypress("put here your def",'Button')
(The def must not have any "")
(Button Left,Right,Down+any letter have to be with '(example)')
In the def it must have to mention the turtle I want to control, Like this:
def left():
p.left(90)
Ive just needed to give more attention to the video, Thats all.
Thanks for reading.
Is there a way you can hold the arrow keys instead of pressing them once every time? I am on python 3.7
@@TokyoEdTech Thank you
Hi, could you tell me why we use turtle.onkey(turnleft,"Left") instead of player.onkey((turnleft,"Left") ? On using player.onkey(turnleft,"Left") it shows the error - 'Turtle' object has no attribute 'onkey'
AMAZING!!! DO MORE!!!
Thank goodness
*_I LIKE TURTLES_*
Hey how do I make a character move while I'm holding down a key?
Thanks man! Btw, amazing vids! Keep up the great work- you really helped me a ton!
In C++ it's a really bad habit using global variables, such as speed in this case. We rather use classes with the variable as a private. Is global variables also bad in python?
Ok, ty for the respond. I did not know that you could use classes in python.
I'm learning python as my second language while C++ being my first, about 2-3 years ago. Allthough a very good tutorial :)
My 7 year old is entertained, my 13 year old is talking smack. Family fun.
Is this Python 3 ?
Could anyone please elaborate the concept of "turtle.listen"?? At what places can we use this method?
Wich ide do you use ?
You’re in luck - I’ve made a video about this exact topic. Enjoy! th-cam.com/video/4bL-lCP2tec/w-d-xo.html
@@TokyoEdTech 😁😅 Thanks
I am having a problem with this code, for some reason my Python Interpreter does not recognize listen or onkey. Is there any suggestions about what I should do?
Thank you for responding, I fixed the problem, I was using Python 3.5 which still had the Turtle module but apparently deleted some of the contents such as listen and onkey. I downloaded Python 2.7 and now it is working perfectly, thank you!
Hey please help me. I am on python 3.8 and turtle.listen and turtle.onkey doesn't work. What command I should use ??
@@TokyoEdTech Thank you so much.
@@ondrejk.3835 can u please share the command
when i press the left arrow its not turning left
If you share your code I can take a look.
same
@@zoki433 Same - see my other comment in this thread.
So, I would have thought a simpler way of changing the turtle's orientation would be to call the player.left() method from within the onkey() method - rather than calling the function you defined as "turnleft".
like so: turtle.onkey(player.left(30), "Left")
However that doesn't work. Is that a design restriction of Python, not allowing recursive method use? Or maybe I'm just not getting something... :-)
@@TokyoEdTech The lambda trick worked, thanks for the tip! You are incredibly helpful with your videos and for you to respond to a comment like that is just above and beyond - well done!
@Tech RK I just commented out the "player left" function, and used this line instead:
turtle.onkey(lambda:player.left(30), "Left")
Hello nice series do you know how to control the speed of 2 turtles. The turtles are both using the global one so of i press up both of their speed goes up one. Please help me with this
You can do:
speed = 3
speed2 = 5
Adjust the rest of the code accordingly.
@@TokyoEdTech thank you for the fast answer! I didnt really think of that but doesnt that just change the animation speed?
@@TokyoEdTech I tried to do your game but with 2 turtles instead its a pretty big challenge
@@Trxsharn Nope. The animation speed is player.speed(0).
@@TokyoEdTech oh yeah i forgot thank you very much! I will try it after im done eating
Great video!!
the window crashes when i run it :(
No error message. Just when I run the program the window pops up and it stops responding
same for me
ngl turtle is extremely east to learn
Indeed.
while(Christian == 'help me a lot'):
print("forever thank you!
@@TokyoEdTech NO , thank you! :)
christian = 'help me a lot'
while Christian == "help me a lot'
print("forever thank you\!
My turtle doesn't move
This is the code
#Turtle graphics game
import turtle
#Set up screen
wn = turtle.Screen()
wn.bgcolor("Black")
#Create player turtle
player = turtle.Turtle()
player.color("Blue")
player.shape("triangle")
player.penup()
#Set speed variable
speed = 1
#Define functions
def turnleft():
player.left(30)
def turnright():
player.right(30)
def increasespeed():
global speed
speed += 1
#Set keyboard bindings
turtle.listen()
turtle.onkey(turnleft,"left")
turtle.onkey(turnright,"right")
turtle.onkey(increasespeed,"Up")
while True:
player.forward(speed)
BRO THANK U SO MUCH
You are quite welcome. Keep on codin'!
turtle.listen()
that didnt work out for ME... why?
this is what i have done:
#Turtle Graphics Game
import turtle
#set up screen
wn = turtle.Screen()
wn.bgcolor('lightgreen')
#Create player turtle
player = turtle.Turtle()
player.color('blue')
player.shape('triangle')
player.penup()
#Set speed variable
speed = 1
#Define functions
def turnrigth():
player.right(30)
def turnleft():
player.left(30)
#Set keyboard bindings
turtle.listen()
turtle.onkey(turnleft, "Left")
turtle.onkey(turnright, "Right")
while True:
player.forward(speed)
delay = raw_input('Press Enter to finish.')
exact code as you.
Can you share the exact error message?
@@TokyoEdTech AttributeError: '' object has no attribute 'listen' on line 16
And the code?
@@TokyoEdTech same problem😅
This is the code👇👇
#Turtle Graphics Game
import turtle
#set up screen
wn = turtle.Screen()
wn.bgcolor('lightgreen')
#Create player turtle
player = turtle.Turtle()
player.color('blue')
player.shape('triangle')
player.penup()
#Set speed variable
speed = 1
#Define functions
def turnrigth():
player.right(30)
def turnleft():
player.left(30)
#Set keyboard bindings
turtle.listen()
turtle.onkey(turnleft, "Left")
turtle.onkey(turnright, "Right")
while True:
player.forward(speed)
delay = raw_input('Press Enter to finish.')
The turnleft does not work. It tells me that is *invalid syntax (, line 24(turtle.onkey(turnleft "left")pylint (syntax-error)[24-1])*. Look at my good for a second please:
import turtle
#screen setup
wn = turtle.Screen()
wn.bgcolor('lightgreen')
#create player turtle
player = turtle.Turtle()
player.color('blue')
player.shape('triangle')
player.penup()
#set speed of player
speed = 1
#define functions
def turnleft():
player.left(30)
#set keyboard stuff
turtle.listen()
turtle.onkey(turnleft "Left")
#This line of code is giving me trouble!
while True:
player.forward(speed)
delay = input("Press Enter To finish: ")
Thank you!
i have read all the comments and have googled countless things but it just does not move when i press a key
import turtle
t = turtle
wn = turtle.Screen()
wn.bgcolor("black")
player1 = t.Turtle()
player1.color("white")
player1.shape("triangle")
player1.penup()
while True:
player1.fd(1)
def turnleft():
player1.left(30)
t.onkey(turnleft, "left")
t.listen()
t.mainloop()
The Daily Compilation try capitalizing the l in "Left"
i got it sorted already thx
@@mitchdg5303 How did you solve it? Can't get it to work
@@Band.Caboose They changed it to onkeypress so try that
while(creative=true):
print ("prefect")
Your code must actually be
while creative==True:
print('perfect')
Nice thought btw :)
*i have an error that turnleft is not recognised
Traceback (most recent call last):
File "C:/Users/HiHi/Documents/k.py", line 16, in
turtle.onkeypress(turnleft, "left")
NameError: name 'turnleft' is not defined
my PROBLEM
help me out
Please would be nice.
I’m happy to take a look, but I need to see the actual code. Please share your code via pastebin.com link so I can download and test it. To learn how, please watch this video and then get back to me: th-cam.com/video/L6AwVuu6O3Y/w-d-xo.html Keep on codin’!
MY TURTLE WONT MOVE I AM ON PYTHON 3.6.1
#Turtle Graphics Game
import turtle
#Set up screen
wn = turtle.Screen()
wn.bgcolor( "lightgreen" )
#Create player turtle
player = turtle.Turtle()
player.color("blue")
player.shape("circle")
player.penup()
#Set speed variable
speed = ("10")
#Define functions
def turnleft():
player.left(30)
#set keyboard bindings
turtle.listen()
turtleonkey(turnleft, "Left")
while True:
player.foward(speed)
delay = raw_input ("press Enter To Finish,")
this is all of it so far :)
My turtle won't moooovvee
#Turtle graphics game
import turtle
#Set up screen
wn = turtle.Screen()
wn.bgcolor("Black")
#Create player turtle
player = turtle.Turtle()
player.color("Blue")
player.shape("triangle")
player.penup()
#Set speed variable
speed = 1
#Define functions
def turnleft():
player.left(30)
def turnright():
player.right(30)
def increasespeed():
global speed
speed += 1
#Set keyboard bindings
turtle.listen()
turtle.onkey(turnleft,"left")
turtle.onkey(turnright,"right")
turtle.onkey(increasespeed,"Up")
while True:
player.forward(speed)
Cannot figure it out
Traceback (most recent call last):
File "C:/Users/Toshiba/Desktop/Goood.py", line 31, in
turtle.onkey(turnleft,"left")
File "", line 1, in onkey
File "C:\Python33\lib\turtle.py", line 1386, in onkey
self._onkeyrelease(fun, key)
File "C:\Python33\lib\turtle.py", line 686, in _onkeyrelease
self.cv.bind("" % key, eventfun)
File "C:\Python33\lib\turtle.py", line 415, in bind
self._canvas.bind(*args, **kwargs)
File "C:\Python33\lib\tkinter\__init__.py", line 1039, in bind
return self._bind(('bind', self._w), sequence, func, add)
File "C:\Python33\lib\tkinter\__init__.py", line 994, in _bind
self.tk.call(what + (sequence, cmd))
_tkinter.TclError: bad event type or keysym "left"
THis is the error help please!
your trackpad for some reason triggers me
import turtle
back = turtle.Screen()
back.bgcolour ('Blue')
what I tried
The error:
back.bgcolour ('Blue')
AttributeError: '_Screen' object has no attribute 'bgcolour'
colour -> color :)
Check spelling colour the American way, color
Great Job..... Thanks For this
ef is_collision(self, other):
if (self.xcor() >= (other.xcor() - 20)) and \
(self.xcor() = (other.ycor() - 20)) and \
(self.ycor()
dosent work in py 3?
try to replace turtle.listen() whit player.listen() and turtle.onkey(turnleft, "Left") whit sc.onkey(turnleft, "Left")
If player.listen() dosent work then try writing your screen variable name like mine is sc then i typed sc.listen() now there is no excuse for programm to not work i hope i fixed your program :D
Christian Thompson can you look up my comment on part 5 plz... I have some bad errors and i typed all correct (variable names are diffrent and that is all)
I don't understand this error
raceback (most recent call last):
File "/Users/Someone/Documents/Python Game L.py", line 32, in
player.forward(speed)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/turtle.py", line 1638, in forward
self._go(distance)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/turtle.py", line 1606, in _go
self._goto(ende)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/turtle.py", line 3160, in _goto
screen._pointlist(self.currentLineItem),
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/turtle.py", line 754, in _pointlist
cl = self.cv.coords(item)
File "", line 1, in coords
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/tkinter/__init__.py", line 2795, in coords
self.tk.call((self._w, 'coords') + args))]
_tkinter.TclError: invalid command name ".!canvas"
Does it happen when you close the window? If so, ignore it.