Learn to Code via Tutorials on Repl.it!

← Back to all posts
How to Make 2D Minecraft in Python - Part One: Moving the Character Around
gatorade322

Making 2D Minecraft With Python: Part One

In this we will be doing the basic movements of the turtle. So first we will do all the imports and starting up stuff like Screen, Turtle, shape, and other stuff. So start by putting this into your code:

Now we’re going to check if the Up button is pushed (using the onkey function so we don’t have to push enter!). So type this in to your code:

Now we can do backwards left and right!

At the end of all the code it should look like a square on a white screen that you can move around with the arrow keys

Voters
YahyaYasir
divyansh042009
zaeemfirdaus
EmranZIRAI
Edwin8557
IsaacSands
DESIMONELOCUS
SnowChristal
JeremyMH5909
JakeIsGreat
Comments
hotnewtop
Sholanki

Hi, I am getting this error after writing down code:

Traceback (most recent call last):
File "main.py", line 3, in <module>
mover = turtle.Turtle()
File "/usr/local/lib/python3.8/turtle.py", line 3812, in init
Turtle._screen = Screen()
File "/usr/local/lib/python3.8/turtle.py", line 3662, in Screen
Turtle._screen = _Screen()
File "/usr/local/lib/python3.8/turtle.py", line 3678, in init
_Screen._root = self._root = _Root()
File "/usr/local/lib/python3.8/turtle.py", line 434, in init
TK.Tk.init(self)
File "/usr/local/lib/python3.8/tkinter/init.py", line 2261, in init
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable

KeyboardInterrupt

Can anyone please help me with this? Sorry, I am a newbie

gatorade322

I don't think you're using python turtle right now. You are using tkinter.

YTAyushTGD

@gatorade322 it doesn't work with python 2.7 or normal python for some reason

gatorade322

turtle is a package, and on repl.it, you need to get the proper repl for the package. If you were running on Linux or something, once you have installed python (sudo apt install python3 I think), you would just import turtle, and it would open a new window.

KirroYT

uh can't move

JeremyMH5909

@KirroYT did u fix

UnityBird20

Hello, Im getting this error ParseError: bad input on line 14

JeremyMH5909

did u fix @UnityBird20

wetcoco

Ehhh, i can't move it! ;-;

xolyon

I was scared that I posted my tutorial without knowledge of this, Phew turns out they are different, nice tutorial anyway!

gatorade322

@xolyon what is your tutorial

xolyon

@gatorade322 Console thingy i am making a 4d version

gatorade322

I would love to see that! I love 4D

xolyon

@gatorade322 I made it in scratch pen, but I am having an issue with mapping in python so yeah, (That's what original tutorial came out by accident)

gatorade322

oh.

JATKitty

woooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooow

SnowChristal

nice

multicoder2021

This code works for me

Source: https://keepthinkup.wordpress.com/programming/python/python-turtle-handling-with-keypressarrow-key/
Edit: I ran this on Python Turtle, not Python 3.8 or 2.7 .

gatorade322

Edit: This doesn't work anymore on Python turtle graphics. Don't ask me why

JeremyMH5909

I don't get an error but in turtle, it just makes my mouse a loading icon and says "Not Responding"

JeremyMH5909

Here is my code:

RowanFromBJC

I had to fix a few indentation errors, but in the end this works.

omarElgohary

when is part 3 coming out?

Ironwolfyyy

when is part 2 coming out?

CodingSquasher

this worked for me!!!!

Leroy01010

nice

neelninja

i cant move it around

gatorade322

what's your problem?

gatorade322

like not in real life, but what's the problem with the coding
=>

neelninja

@gatorade322
well,for startes i type in all of the code and once all of thats done i press run it doesnt give any errors i just cant move around

neelninja

@gatorade322
also when are you going to make part 2?

gatorade322

I did make part two, and also, maybe you could show me the code that you typed

neelninja

@gatorade322
k i will send you a invite

gatorade322

@neelninja I fixed it up. It looked like there were just some indenting problems . . . (:

Fredrichcoder

This is an error on pygame! This code is wrong since it is so obvious that the code is so short

gatorade322

I HAVE TO TELL SO MANY PEOPLE! THIS IS PYTHON TURTLE. NOT PYGAME. NOT TKINTER. NOT ANYTHING BUT TURTLE

Fredrichcoder

@gatorade322 i tried on both still cannot though

gatorade322

@Fredrichcoder did you use python turtle?

Fredrichcoder

@gatorade322 i use pygame

gatorade322

it won't work if you use pygame
pygame doesn't have a turtle, or movable object.

gatorade322

people have had mistakes with this, so I'm anouncing that you use python with turtle

SaiVib

I did in repl.it,and I got this error. I cannot copy and paste the error. I will put the link insted. https://repl.it/@SaiVib/Minecraft

gatorade322

@SaiVib you need to be on python with turtle

YTAyushTGD

Doo you use Tk, Python or Python 2.7

gatorade322

python with turtle

CodingGoose

Thanks! It's a really cool program. I learned a lot of Python Turtle, which I find interesting.

Also, when will the second part come out? I'm really hyped now!

gatorade322

the second part, I kept running in to some hard parts, but I'm almost finished (sneak peak that it's the background), and it should be done by tomorrow!

gatorade322
CodingGoose

@gatorade322 Ok.Thanks! I can't wait! :)

Ironwolfyyy

nice

gatorade322

@HEROBRATT thanks

Codemonkey51

Cool!

gatorade322

thanks

Codemonkey51

Your welcome @gatorade322

gatorade322

For some reason I say thank you a lot. Is that a good thing?

CodingGoose

@gatorade322 Always :)

gatorade322

OK!