Graph
Creates an area for you to draw on. The MAGICAL property this Element has is that you interact with the element using your own coordinate system. This is an important point!! YOU define where the location is for (0,0). Want (0,0) to be in the middle of the graph like a math 4-quadrant graph? No problem! Set your lower left corner to be (-100,-100) and your upper right to be (100,100) and you've got yourself a graph with (0,0) at the center. One of THE coolest of the Elements. Drawing primitives return an "id" that is referenced when you want to operation on that item (e.g. to erase it)
Graph(
canvas_size,
graph_bottom_left,
graph_top_right,
background_color = None,
pad = None,
key = None,
k = None,
tooltip = None,
visible = True,
change_submits = False,
enable_events = False,
drag_submits = False,
metadata = None
)
Parameter Descriptions
Name | Type | Default | Description |
---|---|---|---|
background_color | str | None | background color of the drawing area |
canvas_size | (int, int) | size of the canvas area in pixels | |
change_submits | bool | False | * DEPRICATED DO NOT USE. Use enable_events instead |
drag_submits | bool | False | if True and Events are enabled for the Graph, will report Events any time the mouse moves while button down. When the mouse button is released, you'll get an event = graph key + '+UP' (if key is a string.. if not a string, it'll be made into a tuple) |
enable_events | bool | False | If True then clicks on the Graph are immediately reported as an event. Use this instead of change_submits |
graph_bottom_left | (int, int) | (x,y) The bottoms left corner of your coordinate system | |
graph_top_right | (int, int) | (x,y) The top right corner of your coordinate system | |
k | str or int or tuple or object | None | Same as the Key. You can use either k or key. Which ever is set will be used. |
key | str or int or tuple or object | None | Value that uniquely identifies this element from all other elements. Used when Finding an element or in return values. Must be unique to the window |
metadata | Any | None | User metadata that can be set to ANYTHING |
pad | (int, int or (int, int),(int,int) or int,(int,int)) or ((int, int),int) | None | Amount of padding to put around element in pixels (left/right, top/bottom) or ((left, right), (top, bottom)) or an int. If an int, then it's converted into a tuple (int, int) |
tooltip | str | None | text, that will appear when mouse hovers over the element |
visible | bool | True | set visibility state of the element (Default = True) |
Class Properties
tk_canvas
Returns the underlying tkinter Canvas widget
Parameter DescriptionsName | Type | Default | Description |
---|---|---|---|
RETURN | (tk.Canvas) | The tkinter canvas widget |
Class Methods
def change_coordinates
def draw_arc
def draw_circle
def draw_line
def draw_oval
def draw_point
def draw_rectangle
def draw_rectangle_old
def draw_text
def erase
def expand
def get_stylesheet
def move
def move_figure
def relocate_figure
def set_stylesheet
def update
change_coordinates
Changes the coordinate system to a new one. The same 2 points in space are used to define the coorinate system - the bottom left and the top right values of your graph.
Parameter Descriptions
Name | Type | Default | Description |
---|---|---|---|
graph_bottom_left | (int, int) (x,y) | The bottoms left corner of your coordinate system | |
graph_top_right | (int, int) (x,y) | The top right corner of your coordinate system |
draw_arc
Draws different types of arcs. Uses a "bounding box" to define location
Parameter Descriptions
Name | Type | Default | Description |
---|---|---|---|
arc_color | str | black | color to draw arc with |
bottom_right | (int, int) or Tuple[float, float] | the bottom right point of bounding rectangle | |
extent | float | Andle to end drawing. Used in conjunction with start_angle | |
start_angle | float | Angle to begin drawing. Used in conjunction with extent | |
style | str | None | Valid choices are One of these Style strings- 'pieslice', 'chord', 'arc', 'first', 'last', 'butt', 'projecting', 'round', 'bevel', 'miter' |
top_left | (int, int) or Tuple[float, float] | the top left point of bounding rectangle | |
RETURN | int or None | id returned from tkinter that you'll need if you want to manipulate the arc |
draw_circle
Draws a circle, cenetered at the location provided. Can set the fill and outline colors
Parameter Descriptions
Name | Type | Default | Description |
---|---|---|---|
center_location | (int, int) or Tuple[float, float] | Center location using USER'S coordinate system | |
fill_color | str | None | color of the point to draw |
line_color | str | black | color of the outer line that goes around the circle (sorry, can't set thickness) |
radius | int or float | Radius in user's coordinate values. | |
RETURN | int or None | id returned from tkinter that you'll need if you want to manipulate the circle |
draw_line
Draws a line from one point to another point using USER'S coordinates. Can set the color and width of line
Parameter Descriptions
Name | Type | Default | Description |
---|---|---|---|
color | str | black | Color of the line |
point_from | (int, int) or Tuple[float, float] | Starting point for line | |
point_to | (int, int) or Tuple[float, float] | Ending point for line | |
width | int | 1 | width of line in pixels |
RETURN | int or None | id returned from tktiner or None if user closed the window. id is used when you |
draw_oval
Draws an oval based on coordinates in user coordinate system. Provide the location of a "bounding rectangle"
Parameter Descriptions
Name | Type | Default | Description |
---|---|---|---|
bottom_right | (int, int) or Tuple[float, float] | the bottom right point of bounding rectangle | |
fill_color | str | None | color of the interrior |
line_color | str | None | color of outline of oval |
top_left | (int, int) or Tuple[float, float] | the top left point of bounding rectangle | |
RETURN | int or None | id returned from tkinter that you'll need if you want to manipulate the oval |
draw_point
Draws a "dot" at the point you specify using the USER'S coordinate system
Parameter Descriptions
Name | Type | Default | Description |
---|---|---|---|
color | str | black | color of the point to draw |
point | (int, int) or Tuple[float, float] | Center location using USER'S coordinate system | |
size | int or float | 2 | Radius? (Or is it the diameter?) in user's coordinate values. |
RETURN | int or None | id returned from tkinter that you'll need if you want to manipulate the point |
draw_rectangle
Draw a rectangle given 2 points. Can control the line and fill colors
Parameter Descriptions
Name | Type | Default | Description |
---|---|---|---|
bottom_right | (int, int) or Tuple[float, float] | the bottom right point of rectangle | |
fill_color | str | None | color of the interior |
line_color | str | None | color of outline |
top_left | (int, int) or Tuple[float, float] | the top left point of rectangle | |
RETURN | int or None | int |
draw_rectangle_old
Draw a rectangle given 2 points. Can control the line and fill colors
Parameter Descriptions
Name | Type | Default | Description |
---|---|---|---|
bottom_right | (int, int) or Tuple[float, float] | the bottom right point of rectangle | |
fill_color | str | None | color of the interior |
line_color | str | None | color of outline |
top_left | (int, int) or Tuple[float, float] | the top left point of rectangle | |
RETURN | int or None | int |
draw_text
Draw some text on your graph. This is how you label graph number lines for example
Parameter Descriptions
Name | Type | Default | Description |
---|---|---|---|
angle | float | 0 | Angle 0 to 360 to draw the text. Zero represents horizontal text |
color | str | black | text color |
font | (str or (str, int[, str]) or None) | None | specifies the font family, size, etc. Tuple or Single string format 'name size styles'. Styles: italic * roman bold normal underline overstrike |
location | (int, int) or Tuple[float, float] | location to place first letter | |
text | Any | text to display | |
RETURN | int or None | id returned from tkinter that you'll need if you want to manipulate the text |
erase
Erase the Graph - Removes all figures previously "drawn" using the Graph methods (e.g. DrawText)
expand
WARNING - NOT USED IN PySimpleGUIQt port. Provided as dummy method
Parameter Descriptions
Name | Type | Default | Description |
---|---|---|---|
expand_row | bool | True | If True the row containing the element will also expand. Without this your element is "trapped" within the row |
expand_x | bool | False | If True Element will expand in the Horizontal directions |
expand_y | bool | False | If True Element will expand in the Vertical directions |
RETURN | None | None |
get_stylesheet
Returns the stylesheet for element's associated Qt Widget
Parameter Descriptions
Name | Type | Default | Description |
---|---|---|---|
RETURN | str | stylesheet |
move
Moves the entire drawing area (the canvas) by some delta from the current position. Units are indicated in your coordinate system indicated number of ticks in your coordinate system
Parameter Descriptions
Name | Type | Default | Description |
---|---|---|---|
x_direction | int or float | how far to move in the "X" direction in your coordinates | |
y_direction | int or float | how far to move in the "Y" direction in your coordinates |
move_figure
Moves a previously drawn figure using a "delta" from current position
Parameter Descriptions
Name | Type | Default | Description |
---|---|---|---|
figure | id | Previously obtained figure-id. These are returned from all Draw methods | |
x_direction | int or float | delta to apply to position in the X direction | |
y_direction | int or float | delta to apply to position in the Y direction |
relocate_figure
Moves a previously drawn figure using a "delta" from current position
Parameter Descriptions
Name | Type | Default | Description |
---|---|---|---|
id | id | Previously obtained figure-id. These are returned from all Draw methods | |
x | int or float | delta to apply to position in the X direction | |
y | int or float | delta to apply to position in the Y direction |
set_stylesheet
Sets the stylesheet for a Qt Widget
Parameter Descriptions
Name | Type | Default | Description |
---|---|---|---|
stylesheet | str | Stylesheet (string) to set stylesheet to |
update
Changes some of the settings for the Graph Element. Must call Window.Read
or Window.Finalize
prior
Changes will not be visible in your window until you call window.read or window.refresh.
If you change visibility, your element may MOVE.
Parameter Descriptions
Name | Type | Default | Description |
---|---|---|---|
background_color | str | color of background. Can be in #RRGGBB format or a color name "black" | |
visible | bool | None | set visibility state of the element (Default = True) |