Web Analytics Made Easy - Statcounter
Skip to content

Graph

Graph documentation

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. You can also use float values. To do so, be sure and set the float_values parameter. Mouse click and drag events are possible and return the (x,y) coordinates of the mouse 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,
    p = None,
    change_submits = False,
    drag_submits = False,
    enable_events = False,
    motion_events = False,
    key = None,
    k = None,
    tooltip = None,
    right_click_menu = None,
    expand_x = False,
    expand_y = False,
    visible = True,
    float_values = False,
    border_width = 0,
    metadata = None
)

Parameter Descriptions

Name Type Default Description
background_color str None background color of the drawing area
border_width int 0 width of border around element in pixels. Not normally used for Graph Elements
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
expand_x bool False If True the element will automatically expand in the X direction to fill available space
expand_y bool False If True the element will automatically expand in the Y direction to fill available space
float_values bool False If True x,y coordinates are returned as floats, not ints
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
motion_events bool False If True then if no button is down and the mouse is moved, an event is generated with key = graph key + '+MOVE' (if key is a string, it not a string then a tuple is returned)
p (int, int or (int, int),(int,int) or int,(int,int)) or ((int, int),int) or int None Same as pad parameter. It's an alias. If EITHER of them are set, then the one that's set will be used. If BOTH are set, pad will be used
pad (int, int or (int, int),(int,int) or int,(int,int)) or ((int, int),int) or 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)
right_click_menu List[List[ List[str] or str ]] None A list of lists of Menu items to show when this element is right clicked. See user docs for exact format.
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

key
metadata
tk_canvas
visible
widget

key

Returns key for the element. This is a READONLY property. Keys can be any hashable object (basically anything except a list... tuples are ok, but not lists)

key
Parameter Descriptions

Name Type Default Description
RETURN Any The window's Key

metadata

Metadata is an Element property that you can use at any time to hold any value

metadata
Parameter Descriptions

Name Type Default Description
RETURN Any the current metadata value

tk_canvas

Returns the underlying tkiner Canvas widget

tk_canvas
Parameter Descriptions

Name Type Default Description
RETURN (tk.Canvas) The tkinter canvas widget

visible

Returns visibility state for the element. This is a READONLY property

visible
Parameter Descriptions

Name Type Default Description
RETURN bool Visibility state for element

widget

Returns tkinter widget for the element. This is a READONLY property. The implementation is that the Widget member variable is returned. This is a backward compatible addition

widget
Parameter Descriptions

Name Type Default Description
RETURN (tkinter.Widget) The element's underlying tkinter widget

Class Methods

 def bind
 def block_focus
 def bring_figure_to_front
 def button_press_call_back
 def button_release_call_back
 def change_coordinates
 def delete_figure
 def draw_arc
 def draw_circle
 def draw_image
 def draw_line
 def draw_lines
 def draw_oval
 def draw_point
 def draw_polygon
 def draw_rectangle
 def draw_text
 def erase
 def expand
 def get_bounding_box
 def get_figures_at_location
 def get_next_focus
 def get_previous_focus
 def get_size
 def grab_anywhere_exclude
 def grab_anywhere_include
 def hide_row
 def motion_call_back
 def move
 def move_figure
 def relocate_figure
 def remove_tooltip
 def save_element_screenshot_to_disk
 def send_figure_to_back
 def set_cursor
 def set_focus
 def set_right_click_menu
 def set_size
 def set_tooltip
 def set_vscroll_position
 def unbind
 def unhide_row
 def update

bind

Used to add tkinter events to an Element. The tkinter specific data is in the Element's member variable user_bind_event

bind(
    bind_string,
    key_modifier,
    propagate = True
)

Parameter Descriptions

Name Type Default Description
bind_string str The string tkinter expected in its bind function
key_modifier str Additional data to be added to the element's key when event is returned
propagate bool True If True then tkinter will be told to propagate the event to the element

block_focus

Enable or disable the element from getting focus by using the keyboard. If the block parameter is True, then this element will not be given focus by using the keyboard to go from one element to another. You CAN click on the element and utilize it.

block_focus(
    block = True
)

Parameter Descriptions

Name Type Default Description
block bool True if True the element will not get focus via the keyboard

bring_figure_to_front

Changes Z-order of figures on the Graph. Brings the indicated figure to the front of all other drawn figures

bring_figure_to_front(
    figure
)

Parameter Descriptions

Name Type Default Description
figure int value returned by tkinter when creating the figure / drawing

button_press_call_back

Not a user callable method. Used to get Graph click events. Called by tkinter when button is released

button_press_call_back(
    event
)

Parameter Descriptions

Name Type Default Description
event (event) event info from tkinter. Contains the x and y coordinates of a click

button_release_call_back

Not a user callable method. Used to get Graph click events. Called by tkinter when button is released

button_release_call_back(
    event
)

Parameter Descriptions

Name Type Default Description
event (event) event info from tkinter. Note not used in this method

change_coordinates

Changes the corrdinate 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.

change_coordinates(
    graph_bottom_left,
    graph_top_right
)

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

delete_figure

Remove from the Graph the figure represented by id. The id is given to you anytime you call a drawing primitive

delete_figure(
    id
)

Parameter Descriptions

Name Type Default Description
id int the id returned to you when calling one of the drawing methods

draw_arc

Draws different types of arcs. Uses a "bounding box" to define location

draw_arc(
    top_left,
    bottom_right,
    extent,
    start_angle,
    style = None,
    arc_color = "black",
    line_width = 1,
    fill_color = None
)

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
fill_color str None color to fill the area
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

draw_circle(
    center_location,
    radius,
    fill_color = None,
    line_color = "black",
    line_width = 1
)

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)
line_width int 1 width of the line around the circle, the outline, in pixels
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_image

Places an image onto your canvas. It's a really important method for this element as it enables so much

draw_image(
    filename = None,
    data = None,
    location = (None, None)
)

Parameter Descriptions

Name Type Default Description
data str or bytes None if image is in Base64 format or raw? format then use instead of filename
filename str None if image is in a file, path and filename for the image. (GIF and PNG only!)
location (int, int) or Tuple[float, float] (None, None) the (x,y) location to place image's top left corner
RETURN int or None id returned from tkinter that you'll need if you want to manipulate the image

draw_line

Draws a line from one point to another point using USER'S coordinates. Can set the color and width of line

draw_line(
    point_from,
    point_to,
    color = "black",
    width = 1
)

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_lines

Draw a series of lines given list of points

draw_lines(
    points,
    color = "black",
    width = 1
)

Parameter Descriptions

Name Type Default Description
color str black Color of the line
points List[(int, int) or Tuple[float, float]] list of points that define the polygon
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"

draw_oval(
    top_left,
    bottom_right,
    fill_color = None,
    line_color = None,
    line_width = 1
)

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
line_width int 1 width of the line around the oval, the outline, in pixels
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

draw_point(
    point,
    size = 2,
    color = "black"
)

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_polygon

Draw a polygon given list of points

draw_polygon(
    points,
    fill_color = None,
    line_color = None,
    line_width = None
)

Parameter Descriptions

Name Type Default Description
fill_color str None color of the interior
line_color str None color of outline
line_width int None width of the line in pixels
points List[(int, int) or Tuple[float, float]] list of points that define the polygon
RETURN int or None id returned from tkinter that you'll need if you want to manipulate the rectangle

draw_rectangle

Draw a rectangle given 2 points. Can control the line and fill colors

draw_rectangle(
    top_left,
    bottom_right,
    fill_color = None,
    line_color = None,
    line_width = None
)

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
line_width int None width of the line in pixels
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

draw_text(
    text,
    location,
    color = "black",
    font = None,
    angle = 0,
    text_location = "center"
)

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
text_location enum center "anchor" location for the text. Values start with TEXT_LOCATION_
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)

erase()

expand

Causes the Element to expand to fill available space in the X and Y directions. Can specify which or both directions

expand(
    expand_x = False,
    expand_y = False,
    expand_row = True
)

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

get_bounding_box

Given a figure, returns the upper left and lower right bounding box coordinates

get_bounding_box(
    figure
)

Parameter Descriptions

Name Type Default Description
figure object a previously drawing figure
RETURN Tuple[int, int, int, int] or Tuple[float, float, float, float] upper left x, upper left y, lower right x, lower right y

get_figures_at_location

Returns a list of figures located at a particular x,y location within the Graph

get_figures_at_location(
    location
)

Parameter Descriptions

Name Type Default Description
location (int, int) or Tuple[float, float] point to check
RETURN List[int] a list of previously drawn "Figures" (returned from the drawing primitives)

get_next_focus

Gets the next element that should get focus after this element.

get_next_focus()

Parameter Descriptions

Name Type Default Description
RETURN Element Element that will get focus after this one

get_previous_focus

Gets the element that should get focus previous to this element.

get_previous_focus()

Parameter Descriptions

Name Type Default Description
RETURN Element Element that should get the focus before this one

get_size

Return the size of an element in Pixels. Care must be taken as some elements use characters to specify their size but will return pixels when calling this get_size method.

get_size()

Parameter Descriptions

Name Type Default Description
RETURN (int, int) width and height of the element

grab_anywhere_exclude

Excludes this element from being used by the grab_anywhere feature Handy for elements like a Graph element when dragging is enabled. You want the Graph element to get the drag events instead of the window dragging.

grab_anywhere_exclude()

grab_anywhere_include

Includes this element in the grab_anywhere feature This will allow you to make a Multline element drag a window for example

grab_anywhere_include()

hide_row

Hide the entire row an Element is located on. Use this if you must have all space removed when you are hiding an element, including the row container

hide_row()

motion_call_back

Not a user callable method. Used to get Graph mouse motion events. Called by tkinter when mouse moved

motion_call_back(
    event
)

Parameter Descriptions

Name Type Default Description
event (event) event info from tkinter. Contains the x and y coordinates of a mouse

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

move(
    x_direction,
    y_direction
)

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

move_figure(
    figure,
    x_direction,
    y_direction
)

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

Move a previously made figure to an arbitrary (x,y) location. This differs from the Move methods because it uses absolute coordinates versus relative for Move

relocate_figure(
    figure,
    x,
    y
)

Parameter Descriptions

Name Type Default Description
figure id Previously obtained figure-id. These are returned from all Draw methods
x int or float location on X axis (in user coords) to move the upper left corner of the figure
y int or float location on Y axis (in user coords) to move the upper left corner of the figure

remove_tooltip

Removes a previiously created tooltip for an element

remove_tooltip()

save_element_screenshot_to_disk

Saves an image of the PySimpleGUI window provided into the filename provided

save_element_screenshot_to_disk(
    filename = None
)

Parameter Descriptions

Name Type Default Description
RETURN (PIL.ImageGrab or None) A PIL ImageGrab object that can be saved or manipulated

send_figure_to_back

Changes Z-order of figures on the Graph. Sends the indicated figure to the back of all other drawn figures

send_figure_to_back(
    figure
)

Parameter Descriptions

Name Type Default Description
figure int value returned by tkinter when creating the figure / drawing

set_cursor

Sets the cursor for the current Element. "Cursor" is used in 2 different ways in this call. For the parameter "cursor" it's actually the mouse pointer. If you do not want any mouse pointer, then use the string "none" For the parameter "cursor_color" it's the color of the beam used when typing into an input element

set_cursor(
    cursor = None,
    cursor_color = None
)

Parameter Descriptions

Name Type Default Description
cursor str None The tkinter cursor name
cursor_color str None color to set the "cursor" to

set_focus

Sets the current focus to be on this element

set_focus(
    force = False
)

Parameter Descriptions

Name Type Default Description
force bool False if True will call focus_force otherwise calls focus_set

set_right_click_menu

Sets a right click menu for an element. If a menu is already set for the element, it will call the tkinter destroy method to remove it

set_right_click_menu(
    menu = None
)

Parameter Descriptions

Name Type Default Description
menu List[List[ List[str] or str ]] None A list of lists of Menu items to show when this element is right clicked. See user docs for exact format.

set_size

Changes the size of an element to a specific size. It's possible to specify None for one of sizes so that only 1 of the element's dimensions are changed.

set_size(
    size = (None, None)
)

Parameter Descriptions

Name Type Default Description
size (int, int) (None, None) The size in characters, rows typically. In some cases they are pixels

set_tooltip

Called by application to change the tooltip text for an Element. Normally invoked using the Element Object such as: window.Element('key').SetToolTip('New tip').

set_tooltip(
    tooltip_text
)

Parameter Descriptions

Name Type Default Description
tooltip_text str or None the text to show in tooltip. If None then no tip will be shown

set_vscroll_position

Attempts to set the vertical scroll postition for an element's Widget

set_vscroll_position(
    percent_from_top
)

Parameter Descriptions

Name Type Default Description
percent_from_top float From 0 to 1.0, the percentage from the top to move scrollbar to

unbind

Removes a previously bound tkinter event from an Element.

unbind(
    bind_string
)

Parameter Descriptions

Name Type Default Description
bind_string str The string tkinter expected in its bind function

unhide_row

Unhides (makes visible again) the row container that the Element is located on. Note that it will re-appear at the bottom of the window / container, most likely.

unhide_row()

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. If you want it to remain stationary, use the "layout helper" function "pin" to ensure your element is "pinned" to that location in your layout so that it returns there when made visible.

update(
    background_color = None,
    visible = None
)

Parameter Descriptions

Name Type Default Description
background_color ??? None color of background
visible bool None control visibility of element