Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

screen.onkey python

from turtle import Turtle, Screen

screen = Screen()
screen.setup(1200, 500)

# Ground

ground = Turtle()
ground.speed('fastest')

ground.penup()
ground.goto(-1000, -200)
ground.pendown()
ground.forward(2000)

# Player

player = Turtle()
player.speed('fastest')

PlayerX = -600

def moveX():
    global PlayerX

    screen.onkeypress(None, "w")  # disable handler in handler
    player.clear()
    player.penup()
    player.goto(PlayerX, -99)
    player.pendown()
    player.color("Slate Gray")
    player.begin_fill()
    player.circle(-50)
    player.end_fill()

    PlayerX -= 1

    screen.onkeypress(moveX, "w")  # reenable handler

screen.listen()

moveX()

screen.mainloop()  # change import & use turtle.mainloop() if Python 2
Comment

PREVIOUS NEXT
Code Example
Python :: save screenshot of screen in pygame 
Python :: how to make variable global in python 
Python :: Video to text convertor in python 
Python :: sending email with django 
Python :: remove leading and lagging spaces dataframe python 
Python :: list files in http directory python 
Python :: python logging basicConfig+time 
Python :: Program to find GCD or HCF of two numbers python 
Python :: find pdf encrypted password with python 
Python :: generate rsa key python 
Python :: django queryset exists 
Python :: django filter queryset by date 
Python :: fullscreen cmd with python 
Python :: mse python 
Python :: how to take space separated input in python 
Python :: how to know if the space button has been clicked in python pygame 
Python :: python max function with lambda 
Python :: cv2 rotate image 
Python :: update_or_create django 
Python :: split list in pd dataframe into rows 
Python :: write the output of a function in a txt file 
Python :: python add one month to a date 
Python :: decode binary string python 
Python :: python enum advanced 
Python :: python dict remove duplicates where name are not the same 
Python :: Python Selenium import WebElement 
Python :: python 3.11 release date 
Python :: rename column in pandas with second row 
Python :: What is the use of f in python? 
Python :: exclude serializer 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =