Easy Draw Module
Search…
Property Getting and Setting

Property Getting

object.property_name
To get any property from an Easy Draw object, simply use the variable name of storing the object dot the name of the property.
Example: Getting the radius property from a Regular Polygon object named pentagon
pentagon.radius
Example: Getting the color property from a Text object named title
title.color

Property Setting

object.set_property(property_name = new_value)
To set a property to a new value, you must call the .set_property() method on the object you want to change, identifying the property you want to change and its new value.
Example: Changing the text property of a Text object named title
title.set_property(text = "Player 1 has selected a character...")
Example: Changing the width property of a Rectangle object named box
box.set_property(width = 200)

Examples

In this example we will create a square with a random color and an octagon with default color, "black". Whenever the octagon is clicked, its color will change to the square's color.
To do this, we need to get the color property of the square and set the color property of the octagon.
Get the square's color property -- square.color
Set the octagon's property -- octagon.set_property()
import easy_draw
import random
​
easy_draw.load_canvas()
​
square = easy_draw.Rectangle(
xy = (100, 100),
width = 200,
height = 200,
color = random.choice(["blue", "red", "yellow", "green", "orange", "purple"])
)
​
octagon = easy_draw.RegPolygon(
center_xy=(400,400),
radius=100,
nsides=8
)
​
def click_octagon(event):
global square
global octagon
octagon.set_property(color = square.color)
​
square.event_setup("<Button-1>", click_octagon)
​
easy_draw.end()
​
In this example, we create a growing circle by increasing the circle's radius by 10 each time it is clicked.
Notice how the Circle object's radius property is set to the current cir.radius plus 10.
import easy_draw
​
easy_draw.load_canvas()
​
cir = easy_draw.Circle(
center_xy = (300, 300),
radius = 20
)
​
def click_circle(event):
global cir
cir.set_property(radius = cir.radius + 10)
​
cir.event_setup("<Button-1>", click_circle)
​
easy_draw.end()
​
Export as PDF
Copy link