Python Turtle graphics box doesn't show up
up vote
0
down vote
favorite
This is my code and when I run this code:
from turtle import Turtle
def draw_square():
window = turtle.Screen()
window.bgcolor("red")
brad = turtle.Turtle()
brad.shape("turtle")
brad.color("yellow")
brad.speed(2)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
nothing happens, just the shell appears saying RESTART like you can see in pictures. Help me please!
python turtle-graphics
add a comment |
up vote
0
down vote
favorite
This is my code and when I run this code:
from turtle import Turtle
def draw_square():
window = turtle.Screen()
window.bgcolor("red")
brad = turtle.Turtle()
brad.shape("turtle")
brad.color("yellow")
brad.speed(2)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
nothing happens, just the shell appears saying RESTART like you can see in pictures. Help me please!
python turtle-graphics
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
This is my code and when I run this code:
from turtle import Turtle
def draw_square():
window = turtle.Screen()
window.bgcolor("red")
brad = turtle.Turtle()
brad.shape("turtle")
brad.color("yellow")
brad.speed(2)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
nothing happens, just the shell appears saying RESTART like you can see in pictures. Help me please!
python turtle-graphics
This is my code and when I run this code:
from turtle import Turtle
def draw_square():
window = turtle.Screen()
window.bgcolor("red")
brad = turtle.Turtle()
brad.shape("turtle")
brad.color("yellow")
brad.speed(2)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
nothing happens, just the shell appears saying RESTART like you can see in pictures. Help me please!
python turtle-graphics
python turtle-graphics
edited Nov 9 at 16:34
cdlane
16.8k21043
16.8k21043
asked Nov 9 at 8:18
Hamza Sajid
1
1
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
Please write down the code instead of linking a screenshot. Makes things easier :)
The code is inside a function definition but you didn't call the function anywhere. Try to call it at the end of your program:
from turtle import Turtle
def draw_square(): # function definition
window = turtle.Screen()
...
...
brad.right(90)
draw_square() # call the function
umm thank you for the help but what should i do in order to complete a square ? like i just don,t know what i am missing right now...:(
– Hamza Sajid
Nov 9 at 9:51
@HamzaSajid you say that the square is not "complete", can you describe what shape is being drawn? Edit your initial question with more detailed info.
– user2464424
Nov 9 at 10:10
add a comment |
up vote
0
down vote
There are problems with your import
code:
from turtle import Turtle
it is inconsistent with your usage:
window = turtle.Screen()
brad = turtle.Turtle()
Since you only imported Turtle
from turtle, neither of these lines will work. You can do either:
import turtle
window = turtle.Screen()
brad = turtle.Turtle()
or (preferably if you want to only use the object-oriented turtle):
from turtle import Screen, Turtle
window = Screen()
brad = Turtle()
The next problem with your import
is that it's not consistent with the import
cited in the Python Shell error message:
import Turtle
ImportError: No module named Turtle
which might mean the code you're looking at and the code you're running aren't the same. Now let's try to put together a consistent, complete (Python 2, I'm assuming) program from your code:
from turtle import Screen, Turtle, mainloop
def draw_square(turtle):
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
window = Screen()
window.bgcolor("red")
brad = Turtle()
brad.shape("turtle")
brad.color("yellow")
brad.speed(2)
draw_square(brad)
mainloop()
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Please write down the code instead of linking a screenshot. Makes things easier :)
The code is inside a function definition but you didn't call the function anywhere. Try to call it at the end of your program:
from turtle import Turtle
def draw_square(): # function definition
window = turtle.Screen()
...
...
brad.right(90)
draw_square() # call the function
umm thank you for the help but what should i do in order to complete a square ? like i just don,t know what i am missing right now...:(
– Hamza Sajid
Nov 9 at 9:51
@HamzaSajid you say that the square is not "complete", can you describe what shape is being drawn? Edit your initial question with more detailed info.
– user2464424
Nov 9 at 10:10
add a comment |
up vote
0
down vote
Please write down the code instead of linking a screenshot. Makes things easier :)
The code is inside a function definition but you didn't call the function anywhere. Try to call it at the end of your program:
from turtle import Turtle
def draw_square(): # function definition
window = turtle.Screen()
...
...
brad.right(90)
draw_square() # call the function
umm thank you for the help but what should i do in order to complete a square ? like i just don,t know what i am missing right now...:(
– Hamza Sajid
Nov 9 at 9:51
@HamzaSajid you say that the square is not "complete", can you describe what shape is being drawn? Edit your initial question with more detailed info.
– user2464424
Nov 9 at 10:10
add a comment |
up vote
0
down vote
up vote
0
down vote
Please write down the code instead of linking a screenshot. Makes things easier :)
The code is inside a function definition but you didn't call the function anywhere. Try to call it at the end of your program:
from turtle import Turtle
def draw_square(): # function definition
window = turtle.Screen()
...
...
brad.right(90)
draw_square() # call the function
Please write down the code instead of linking a screenshot. Makes things easier :)
The code is inside a function definition but you didn't call the function anywhere. Try to call it at the end of your program:
from turtle import Turtle
def draw_square(): # function definition
window = turtle.Screen()
...
...
brad.right(90)
draw_square() # call the function
answered Nov 9 at 8:33
user2464424
8811820
8811820
umm thank you for the help but what should i do in order to complete a square ? like i just don,t know what i am missing right now...:(
– Hamza Sajid
Nov 9 at 9:51
@HamzaSajid you say that the square is not "complete", can you describe what shape is being drawn? Edit your initial question with more detailed info.
– user2464424
Nov 9 at 10:10
add a comment |
umm thank you for the help but what should i do in order to complete a square ? like i just don,t know what i am missing right now...:(
– Hamza Sajid
Nov 9 at 9:51
@HamzaSajid you say that the square is not "complete", can you describe what shape is being drawn? Edit your initial question with more detailed info.
– user2464424
Nov 9 at 10:10
umm thank you for the help but what should i do in order to complete a square ? like i just don,t know what i am missing right now...:(
– Hamza Sajid
Nov 9 at 9:51
umm thank you for the help but what should i do in order to complete a square ? like i just don,t know what i am missing right now...:(
– Hamza Sajid
Nov 9 at 9:51
@HamzaSajid you say that the square is not "complete", can you describe what shape is being drawn? Edit your initial question with more detailed info.
– user2464424
Nov 9 at 10:10
@HamzaSajid you say that the square is not "complete", can you describe what shape is being drawn? Edit your initial question with more detailed info.
– user2464424
Nov 9 at 10:10
add a comment |
up vote
0
down vote
There are problems with your import
code:
from turtle import Turtle
it is inconsistent with your usage:
window = turtle.Screen()
brad = turtle.Turtle()
Since you only imported Turtle
from turtle, neither of these lines will work. You can do either:
import turtle
window = turtle.Screen()
brad = turtle.Turtle()
or (preferably if you want to only use the object-oriented turtle):
from turtle import Screen, Turtle
window = Screen()
brad = Turtle()
The next problem with your import
is that it's not consistent with the import
cited in the Python Shell error message:
import Turtle
ImportError: No module named Turtle
which might mean the code you're looking at and the code you're running aren't the same. Now let's try to put together a consistent, complete (Python 2, I'm assuming) program from your code:
from turtle import Screen, Turtle, mainloop
def draw_square(turtle):
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
window = Screen()
window.bgcolor("red")
brad = Turtle()
brad.shape("turtle")
brad.color("yellow")
brad.speed(2)
draw_square(brad)
mainloop()
add a comment |
up vote
0
down vote
There are problems with your import
code:
from turtle import Turtle
it is inconsistent with your usage:
window = turtle.Screen()
brad = turtle.Turtle()
Since you only imported Turtle
from turtle, neither of these lines will work. You can do either:
import turtle
window = turtle.Screen()
brad = turtle.Turtle()
or (preferably if you want to only use the object-oriented turtle):
from turtle import Screen, Turtle
window = Screen()
brad = Turtle()
The next problem with your import
is that it's not consistent with the import
cited in the Python Shell error message:
import Turtle
ImportError: No module named Turtle
which might mean the code you're looking at and the code you're running aren't the same. Now let's try to put together a consistent, complete (Python 2, I'm assuming) program from your code:
from turtle import Screen, Turtle, mainloop
def draw_square(turtle):
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
window = Screen()
window.bgcolor("red")
brad = Turtle()
brad.shape("turtle")
brad.color("yellow")
brad.speed(2)
draw_square(brad)
mainloop()
add a comment |
up vote
0
down vote
up vote
0
down vote
There are problems with your import
code:
from turtle import Turtle
it is inconsistent with your usage:
window = turtle.Screen()
brad = turtle.Turtle()
Since you only imported Turtle
from turtle, neither of these lines will work. You can do either:
import turtle
window = turtle.Screen()
brad = turtle.Turtle()
or (preferably if you want to only use the object-oriented turtle):
from turtle import Screen, Turtle
window = Screen()
brad = Turtle()
The next problem with your import
is that it's not consistent with the import
cited in the Python Shell error message:
import Turtle
ImportError: No module named Turtle
which might mean the code you're looking at and the code you're running aren't the same. Now let's try to put together a consistent, complete (Python 2, I'm assuming) program from your code:
from turtle import Screen, Turtle, mainloop
def draw_square(turtle):
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
window = Screen()
window.bgcolor("red")
brad = Turtle()
brad.shape("turtle")
brad.color("yellow")
brad.speed(2)
draw_square(brad)
mainloop()
There are problems with your import
code:
from turtle import Turtle
it is inconsistent with your usage:
window = turtle.Screen()
brad = turtle.Turtle()
Since you only imported Turtle
from turtle, neither of these lines will work. You can do either:
import turtle
window = turtle.Screen()
brad = turtle.Turtle()
or (preferably if you want to only use the object-oriented turtle):
from turtle import Screen, Turtle
window = Screen()
brad = Turtle()
The next problem with your import
is that it's not consistent with the import
cited in the Python Shell error message:
import Turtle
ImportError: No module named Turtle
which might mean the code you're looking at and the code you're running aren't the same. Now let's try to put together a consistent, complete (Python 2, I'm assuming) program from your code:
from turtle import Screen, Turtle, mainloop
def draw_square(turtle):
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
window = Screen()
window.bgcolor("red")
brad = Turtle()
brad.shape("turtle")
brad.color("yellow")
brad.speed(2)
draw_square(brad)
mainloop()
answered Nov 9 at 16:31
cdlane
16.8k21043
16.8k21043
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53222049%2fpython-turtle-graphics-box-doesnt-show-up%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown