Adding Geometric Objects to a GUI4sher Project
GUI4sher knows about these geometric object:
· circle
· rectangle
· oval
· line
· dashed_line
· polygon
You add them to a GUI4sher project by using a place function.
For example in this figure:
The place_circle function placed a circle called red_circle in the graphics window. You don’t need the parameters above. If you just type place_circle() it will ask you for the name of your circle. You need the name so you can modify or delete the circle later. The name must be a valid python variable name so it can not have spaces and requires alpha-numeric characters or ‘_’ and can not start with a number or match a python keyword like ‘if’. Below is a simple place_circle function call:
Once enter is typed it then asks for the position of the center of the circle and a point on its edge:
The functions to put geometric objects in the graphics window are:
· place_circle()
· place_rectangle()
· place_oval()
· place_line()
· place_dashed_line()
· place_polygon()
You place rectangles in the graphics area of a GUI4sher project by clicking on two opposite corners. Once you name your rectangle it asks you to click on the first corner. Guide lines appear when it asks you to click so that you can line up GUI4sher objects. In the figure below the guidelines are for placing the rectangle around the circle.
Then you it asks you to click on the diagonal corner it It leaves a dot to show you where the first corner was. The dot will disappear when you create the rectangle with the second click.
This time the name of the rectangle was put in the ()’s in quotes.
You can modify the width of the border with the set_width method. You use the name of the object followed by a period followed by the word set_width.
A call to set_width looks like this:
demo_rectangle.set_width(5)
This tells GUI4sher to make the border 5 pixels wide.
You can change the color of the border by using the set_outline method. You don’t need quotes for common colors like red.
If you want a more exotic color like spring green you will need to quote it.
The predefined colors are:
·
red
= 'red'
·
green = 'green'
·
blue
= 'blue'
· white = 'white'
· black = 'black'
·
gray = 'gray'
·
orange = 'orange'
·
purple
= 'purple'
·
violet
= 'violet'
·
yellow = 'yellow'
·
brown = 'brown'
·
cyan
= 'cyan'
·
magenta
= 'magenta'
·
pink
= 'pink'
You can change the color of the inside of an object by using the set_fill method as show below:
Contents