adettiX
adettiX

Reputation: 21

I am trying to create a rectangle with width = 100 and length = 50 using graphic.py library. I am a bit confused on how to specify the length

I am trying to create a rectangle with width = 100 and length = 50 using graphics.py library. I am a bit confused on how to specify the length. Here's what I have so far:

main ():
 win = GraphWin("window", 300, 300)
 rec = Rectangle (Point (250,250), Point(200, 200))
 rec.setWidth (50)
 rec.draw(win)

Upvotes: 0

Views: 875

Answers (1)

Prune
Prune

Reputation: 77847

In short, read the documentation. SetWidth changes the line thickness, not the rectangle size.

The rectangle dimensions are entirely determined by the two opposing corners you specify when you instantiate the object. I'll change your values to illustrate:

rec = Rectangle (Point(300, 200), Point(100, 50))

This defines a rectangle with opposite corners at the given points.

The width (x direction) is abs(300-100) = 200

The height (y direction) is abs(200-50) = 150

Does that clear up your confusion?

Upvotes: 1

Related Questions