TestingDocs.com
    Software Testing website
    • Automation
      • Selenium
      • JBehave Framework
    • Tutorials
      • MySQL Tutorials
      • Testlink
      • Maven
      • Git
    • IDEs
      • IntelliJ IDEA
      • Eclipse
    • Flowcharts
      • Flowgorithm
      • Raptor
    • About

    Python

    Python Turtle Graphics

    Python Tutorials

    Introduction

    Turtle module in Python can be used to create simple shapes and graphics. Turtle graphics is used to make different shapes and drawing curves. In this post, we will see some sample programs to draw different shapes using Turtle.

    Getting Started

    You need to import the turtle module to start using it. A turtle object can draw lines of various sizes using the in-built methods. The turtle lives in the graphics window and the location is denoted by x and y. Turtles also have orientation i.e angle w.r.t x-axis at which they head.

    import turtle

    The function Screen() returns a singleton object of a  TurtleScreen subclass. This function should be used when the turtle used as a standalone tool for doing graphics.

    Sample code to draw Square

    Steps to create the program.

    • Launch PyCharm IDE.
    • Create a project and add a file. say turtleProgram.py

    Code Listing

    Add the below program code.

    import turtle
    
    
    # main
    def main():
     screen = turtle.Screen()
     t = turtle.Turtle()
     square(t, 100)
     screen.exitonclick()
    
    
    # square
    def square(t, size):
     t.pendown()
     # loop
     for _ in range(4):
     t.forward(size)
     t.right(90)
     t.penup()
    
    
    if __name__ == '__main__':
     main()

    Run the program. Right-click on the program window and choose Run option.

    Program Output

    Turtle Square Program

    Related Posts

    PyCharm Popular Python IDE UX

    Python /

    Popular Python IDEs

    Python Libraries for Data Science

    Python /

    Python Libraries for Data Science

    Download Python Windows 11

    Python /

    Download & Install Python on Windows 11

    Spyder IDE Features

    Python /

    Spyder IDE Features

    Spyder Python IDE

    Python /

    Install Spyder Python IDE

    ‹ Python Language Features› Read file in Python

    Recent Posts

    • Running Tests in Parallel with Selenium Grid
    • Advanced Selenium Features
    • Locating Web Elements
    • Running the Test Script
    • Writing Your First Selenium Test Script
    • Getting Started with Selenium Automation Testing
    • Setting Up the Environment
    • How can you monitor the Quality Assurance Audit?
    • Leveraging LambdaTest with Appium 2.0
    • Appium 2.0 Plugins ListAppium 2.0 Plugins
    • Touch Actions and Multi-Touch Actions
    • Changes in Drivers and Classes
    • Appium Inspector
    • Capabilities in Appium 2.0
    • Appium 2.0 Driver ListAppium 2.0 Driver Installation & Management
    CyberLink Multimedia Software

    Back to Top

    Links

    • Contact
    • Privacy Policy
    • Cookie Policy

    www.TestingDocs.com