Ask coding questions

← Back to all posts
It is not working
[deleted]

I coded this below, and when i click on the canvas, it is not working. Is there an extra command I need to add?

Answered by Coder100 [earned 5 cycles]
View Answer
Voters
spas12
Aivoybia
Comments
hotnewtop
Coder100

yay! I fixed it here

So basically, instead of left do Left (idk why)

also, you forgot to set the colormode to 255, it defaults to 1.

[deleted]

@Coder100 well, on the coding website i use for online class, i can hold the arrow key, and it goes on until you want it to stop

[deleted]

@Coder100 and also, the graphics system is kinda bad, do you know if you can make it better?

Coder100

nope, you could just make a python turtle here, however for speed. @pythoder

DEMONul1234

Try using that for movement:
def up():
palate_a.setheading(90)
palate_a.forward(speed)
def down():
palate_a.setheading(270)
palate_a.forward(speed)
def left():
palate_a.setheading(180)
palate_a.forward(speed)
def right():
palate_a.setheading(0)
palate_a.forward(speed)

win.onkey(up, 'w')
win.onkey(down,'s')
win.onkey(right, 'd')
win.onkey(left, 'a')

win.listen()

also make sure to add:
while True:
win.update()
do not forget about win.mainloop()

DEMONul1234

@DEMONul1234 Of course it is my code, but you can change stuff here and there to match your code. e.g. palate_a is a created square inside of my programme. Just to give you a hint as to what my whole code looks like, here's it:

import turtle, os

win = turtle.Screen()
win.setup(800,600)
win.bgcolor('brown')
win.addshape(os.path.expanduser("C:/Games/c3.gif"))
win.title('My first game')
win.tracer(0)
win.bgpic("C:/Games/space.gif")

palate_a = turtle.Turtle()
palate_a.color('purple')
palate_a.shape(os.path.expanduser("C:/Games/c3.gif"))
palate_a.shapesize(stretch_len= 5, stretch_wid= 10)
palate_a.setposition(0,0)
palate_a.speed(10)
palate_a.penup()
lista = [palate_a]

speed = 10
def up():
palate_a.setheading(90)
palate_a.forward(speed)
def down():
palate_a.setheading(270)
palate_a.forward(speed)
def left():
palate_a.setheading(180)
palate_a.forward(speed)
def right():
palate_a.setheading(0)
palate_a.forward(speed)

class Action_Change_Backgroun:
def init(self, mouse_clic):
self.mouse_clic = mouse_clic
xb = print('good')
Action_mouse = Action_Change_Backgroun(win.onscreenclick(xb,1))
Action_Primary = Action_mouse.mouse_clic

#win.onscreenclick(init(self,clickaction))
win.onkey(up, 'w')
win.onkey(down,'s')
win.onkey(right, 'd')
win.onkey(left, 'a')
win._onscreenclick(Action_Primary, 3)

win.listen()

while True:
win.update()

win.mainloop()

Muffinlavania

@DEMONul1234 dude... your telling him to give up on all of his code and use yours

DEMONul1234

@Muffinlavania Nope, I'm not :) I just told him to use it as an example in order to check how one can assign a key to a certain function, thats all.

Muffinlavania

I get an error, probably because of this

I would do

If it still doesnt work after this fix i can still help, but this be it!

DEMONul1234

@Muffinlavania Actually "Up" works fine as an key name, must be sth wrong with the code