Location

All Locations in pyDraw are wrapped with this class, however some methods and constructors will automatically convert tuples to Locations automatically.

Initialization

Locations can be initialized with two coordinates, a tuple, another location, or by specifying only one coordinate (such as x or y), defaulting the other coordinate's value to zero.

location = Location(0, 0)  # Two arguments
location = Location((200, 100))  # A single tuple
location = Location(another_location)  # Copy constructor

location = Location(x=100)  # Create a location at (100, 0)

Values

There is a variety of ways to retrieve the values from a Location instance:

location.x()  # Get the x-coordinate
location.y()  # Get the y-coordinate

Locations are also readable as tuples:

location[0]  # Get the x-coordinate
location[1]  # Get the y-coordinate

Changing Locations

The methods above can also be used to modify coordinates:

You can also call the handy .move() and .moveto() methods:

Advanced

It is possible to convert to turtle-based coordinates by calling:

Or to convert to Tkinter:

Last updated

Was this helpful?