Skip to content
Sign UpLog In
This post is read-only. Explore Repls and connect with other creators on Community.View Community
The info in this post might be out of date, check out our docs instead. View docs
1

It is not working

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

2 years ago

Voters

spas12
spas12
Aivoybia
Aivoybia

Comments

TopNew
1
Coder100
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.

2 years ago
1

@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

2 years ago
1

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

2 years ago
1
Coder100
Coder100

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

@pythoder

2 years ago
1
DEMONul1234
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()

2 years ago
1
DEMONul1234
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()

2 years ago
1
Muffinlavania
Muffinlavania

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

2 years ago
1
DEMONul1234
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.

2 years ago
1
Muffinlavania
Muffinlavania

I get an error, probably because of this

screen.onkey(tF, "up") screen.onkey(tB, "down") screen.onkey(tL, "left") screen.onkey(tR, "right")

I would do

screen.onkey(tF, "up arrow") screen.onkey(tB, "down arrow") screen.onkey(tL, "left arrow") screen.onkey(tR, "right arrow")

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

2 years ago
1
DEMONul1234
DEMONul1234

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

2 years ago
Load more