Question

8. Create the following three labeled rectangular buttons using turtle graphics using the write method (eg, t.write(Hi!)).
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

Note: Please maintain proper code spacing (indentation), just copy the code part and paste it in your compiler/IDE directly, no modifications required.

#code

import turtle

#creating a list containing button labels
labels=['Start','Stop','Pause']
#creating a turtle
t=turtle.Turtle()
#pen up
t.up()
#moving to (-200,0)
t.goto(-200,0)
#looping for len(labels) times
for i in range(len(labels)):
    #pen down
    t.down()
    #looping to draw a rectangle
    for j in range(2):
        #moving forward 100 spaces, turning right, moving forward 50 spaces, turning right
        t.forward(100)
        t.right(90)
        t.forward(50)
        t.right(90)
    #recording current position
    pos=t.pos()
    #pen up
    t.up()
    #moving to center of current rectangle
    t.goto(pos[0]+50,pos[1]-30)
    #pen down
    t.down()
    #writing current label, center aligned
    t.write(labels[i],align='center')
    #pen up
    t.up()
    #moving to draw next rectangle, 20 spaces away from end of previous rectangle
    t.goto(pos[0]+120,pos[1])

#hiding turtle
t.ht()
#finishing off
turtle.done()

#OUTPUT

Python Turtle Graphics Start Stop Pause

Add a comment
Know the answer?
Add Answer to:
8. Create the following three labeled rectangular buttons using turtle graphics using the write method (eg,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT