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.
1
location = Location(0, 0) # Two arguments
2
location = Location((200, 100)) # A single tuple
3
location = Location(another_location) # Copy constructor
4
5
location = Location(x=100) # Create a location at (100, 0)
Copied!

Values

There is a variety of ways to retrieve the values from a Location instance:
1
location.x() # Get the x-coordinate
2
location.y() # Get the y-coordinate
Copied!
Locations are also readable as tuples:
1
location[0] # Get the x-coordinate
2
location[1] # Get the y-coordinate
Copied!

Changing Locations

The methods above can also be used to modify coordinates:
1
location.x(new_x) # Set a new x-coordinate value
2
location.y(new_y) # Set a new y-coordinate value
Copied!
You can also call the handy .move() and .moveto() methods:
1
location.move(dx, dy) # Move the location by passed values
2
location.move(dx=100) # Only move the x-coordinate by +100
3
4
location.moveto(x, y) # Move to a new position
5
location.moveto(y=100) # Change the y-coordinate to 100
Copied!

Advanced

It is possible to convert to turtle-based coordinates by calling:
1
turtle_location = screen.create_location(location)
Copied!
Or to convert to Tkinter:
1
tkinter_location = screen.canvas_location(location)
Copied!
Last modified 7mo ago