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!



error description










share|improve this question




























    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!



    error description










    share|improve this question


























      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!



      error description










      share|improve this question















      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!



      error description







      python turtle-graphics






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 9 at 16:34









      cdlane

      16.8k21043




      16.8k21043










      asked Nov 9 at 8:18









      Hamza Sajid

      1




      1
























          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





          share|improve this answer





















          • 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




















          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()





          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            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

























            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





            share|improve this answer





















            • 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

















            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





            share|improve this answer





















            • 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















            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





            share|improve this answer












            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






            share|improve this answer












            share|improve this answer



            share|improve this answer










            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




















            • 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














            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()





            share|improve this answer

























              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()





              share|improve this answer























                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()





                share|improve this answer












                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()






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 9 at 16:31









                cdlane

                16.8k21043




                16.8k21043






























                    draft saved

                    draft discarded




















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    這個網誌中的熱門文章

                    Xamarin.form Move up view when keyboard appear

                    Post-Redirect-Get with Spring WebFlux and Thymeleaf

                    JBPM : POST request for execute process go wrong