My Project
Public Member Functions | List of all members
DrawingPanel.DrawingPanel Class Reference

A DrawingPanel object represents a simple interface for creating graphical windows in Python for drawing shapes, lines, images, and colors. More...

Public Member Functions

def __init__ (self, window, width=500, height=500, background="white", **options)
 Constructs a panel of a given width, height, and optional background color. More...
 
def get_mouse_x (self)
 
def get_mouse_y (self)
 
def animate (self, time, func)
 
def add_key_listener (self, function, event_type="press")
 Attaches the given function to be called when keyboard events occur in this DrawingPanel window. More...
 
def add_mouse_listener (self, function, event_type="click")
 Attaches the given function to be called when mouse events occur in this DrawingPanel window. More...
 
def clear (self)
 Erases all shapes from the panel and fills it with its background color.
 
def draw_arc (self, x, y, w, h, start_angle, extent, color="", **options)
 Draws an outlined arc (a partial oval). More...
 
def draw_image (self, filename, x=0, y=0, w=0, h=0, **options)
 Draws an image from a file or Image object with its top-left corner at the given (x, y) pixel. More...
 
def draw_line (self, x1, y1, x2, y2, color="", **options)
 Draws a line between the two given points (x1, y1) and (x2, y2). More...
 
def draw_oval (self, x, y, w, h, color="", **options)
 Draws an oval the given size with its top-left corner at the given (x, y) pixel. More...
 
def draw_pixel (self, x, y, color="", **options)
 Changes the color at the given (x, y) pixel. More...
 
def draw_polyline (self, *coords, **options)
 Draws a group of lines between the given coordinates passed as individual x/y coordinate parameters or (x,y) tuples. More...
 
def draw_polygon (self, *coords, **options)
 Draws an outlined polygon between the given coordinates passed as individual x/y coordinate parameters or (x,y) tuples. More...
 
def draw_rect (self, x, y, w, h, color="", **options)
 Draws a rectangle of the given size with its top-left corner at the given (x, y) pixel. More...
 
def draw_rectangle (self, x, y, w, h, color="", **options)
 Draws a rectangle of the given size with its top-left corner at the given (x, y) pixel. More...
 
def draw_string (self, text, x, y, color="", font="", **options)
 Draws a text string with its top-left corner at the given (x, y) pixel. More...
 
def fill_arc (self, x, y, w, h, start_angle, extent, color="", **options)
 Draws a filled arc (a partial oval). More...
 
def fill_oval (self, x, y, w, h, color="", **options)
 Draws a filled oval of the given size with its top-left corner at the given (x, y) pixel. More...
 
def fill_polygon (self, *coords, **options)
 Draws a filled polygon between the given coordinates passed as individual x/y coordinate parameters or (x,y) tuples. More...
 
def fill_rect (self, x, y, w, h, color="", **options)
 Draws a filled rectangle of the given size with its top-left corner at the given (x, y) pixel. More...
 
def fill_rectangle (self, x, y, w, h, fill="", color="", **options)
 Draws a filled rectangle of the given size with its top-left corner at the given (x, y) pixel. More...
 
def background (self)
 The panel's background color. More...
 
def get_background (self)
 Returns the panel's background color. More...
 
def background_rgb (self)
 The panel's background color as an RGB tuple such as (255, 0, 192). More...
 
def get_background_rgb (self)
 Returns the panel's background color as an RGB tuple. More...
 
def color (self)
 The default color used to outline drawn shapes. More...
 
def get_color (self)
 Returns the default color used to outline drawn shapes. More...
 
def fill_color (self)
 The default color used to fill in shapes. More...
 
def get_fill_color (self)
 Returns the default color used to fill in shapes. More...
 
def font (self)
 The font used for drawn strings. More...
 
def get_font (self)
 Returns the font used for drawn strings. More...
 
def foreground (self)
 The default color used to outline drawn shapes. More...
 
def get_foreground (self)
 Returns the default color used to outline drawn shapes. More...
 
def height (self)
 The height of the panel's canvas area. More...
 
def get_height (self)
 Returns the height of the panel's canvas area. More...
 
def outline_color (self)
 The default color used to outline drawn shapes. More...
 
def get_outline_color (self)
 Returns the default color used to outline drawn shapes. More...
 
def get_pixel (self, x, y)
 Returns the RGB color of the given (x, y) pixel on the canvas as a 3-tuple of three integers from 0-255 representing the Red, Green, and Blue components. More...
 
def get_pixel_color (self, x, y)
 Returns the RGB color of the given (x, y) pixel on the canvas as a string such as "#ff00ff". More...
 
def get_pixel_color_rgb (self, x, y)
 Returns the RGB color of the given (x, y) pixel on the canvas as a 3-tuple of three integers from 0-255 representing the Red, Green, and Blue components. More...
 
def pixels (self)
 A 2D list storing the RGB colors of every pixel on the canvas as a 3-tuple of three integers from 0-255 representing the Red, Green, and Blue components. More...
 
def pixel_colors (self)
 A 2D list storing the RGB colors of every pixel on the canvas as strings such as "#ff00ff". More...
 
def get_pixels (self)
 Returns a 2D list storing the RGB colors of every pixel on the canvas as a 3-tuple of three integers from 0-255 representing the Red, Green, and Blue components. More...
 
def get_pixel_colors (self)
 Returns a 2D list storing the RGB colors of every pixel on the canvas as a string such as "#ff00ff". More...
 
def size (self)
 A 2-element tuple of the width and height of the panel's canvas area. More...
 
def get_size (self)
 Returns a 2-element tuple of the width and height of the panel's canvas area. More...
 
def stroke (self)
 The width that will be used to draw lines on future shapes. More...
 
def get_stroke (self)
 Returns the width that will be used to draw lines on future shapes. More...
 
def stroke_width (self)
 The width that will be used to draw lines on future shapes. More...
 
def get_stroke_width (self)
 Returns the width that will be used to draw lines on future shapes. More...
 
def width (self)
 The width of the panel's canvas area. More...
 
def get_width (self)
 Returns the width of the panel's canvas area. More...
 
def background (self, value)
 Sets the panel's background color to be the given color, as a string such as "yellow" or "black" or "yellow" or "#ff00cc".
 
def set_background (self, *args)
 Sets the panel's background color to be the given color. More...
 
def color (self, value)
 Sets the color used to outline future drawn shapes. More...
 
def set_color (self, *args)
 Sets the color used to outline future drawn shapes. More...
 
def fill_color (self, value)
 Sets the color used to fill in future drawn shapes. More...
 
def set_fill_color (self, *args)
 Sets the color used to fill in future drawn shapes. More...
 
def font (self, value)
 Sets the font used for future drawn strings. More...
 
def set_font (self, font)
 Sets the font used for future drawn strings. More...
 
def foreground (self, value)
 Sets the color used to outline and fill future drawn shapes. More...
 
def set_foreground (self, *args)
 Sets the color used to outline and fill future drawn shapes. More...
 
def outline_color (self, value)
 Sets the color used to outline future drawn shapes. More...
 
def set_outline_color (self, *args)
 Sets the color used to outline future drawn shapes. More...
 
def set_pixel (self, x, y, color="", **options)
 Changes the color at the given (x, y) pixel. More...
 
def pixels (self, px)
 Sets the RGB values of all pixels in this panel's canvas based on the values in the given 2D list. More...
 
def set_pixels (self, pixels)
 Sets the RGB values of all pixels in this panel's canvas based on the values in the given 2D list. More...
 
def pixel_colors (self, px)
 Sets the RGB values of all pixels in this panel's canvas based on the values in the given 2D list. More...
 
def set_pixel_colors (self, pixels)
 Sets the RGB values of all pixels in this panel's canvas based on the values in the given 2D list. More...
 
def stroke (self, width)
 Sets the width that will be used to draw lines on future shapes. More...
 
def set_stroke (self, width)
 Sets the width that will be used to draw lines on future shapes. More...
 
def stroke_width (self, width)
 Sets the width that will be used to draw lines on future shapes. More...
 
def set_stroke_width (self, width)
 Sets the width that will be used to draw lines on future shapes. More...
 
def sleep (self, ms)
 Causes the DrawingPanel to pause for the given number of milliseconds. More...
 
def pack (self, padding_top=0, padding_right=0, padding_bottom=0, padding_left=0, side='')
 Adds this canvas to the frame in the left, or right if side is specified. More...
 

Detailed Description

A DrawingPanel object represents a simple interface for creating graphical windows in Python for drawing shapes, lines, images, and colors.

The DrawingPanel also supports getting and setting the RGB values of individual pixels, which makes it useful for learning about various looping and 2D list- processing algorithms.

See PyDoc comments for individual functions below for more information.

This library is based on Python's Tkinter GUI system. In particular, the drawing surface used by DrawingPanel is a Tkinter Canvas object, and many of our functions are wrappers around Tkinter Canvas functions.

The DrawingPanel supports properties like color, background, width, height, etc. that can be accessed/modified either using traditional methods like get_color and set_background, or as properties named color or background.

Author
: Marty Stepp, Stanford University
: Allison Obourn, University of Arizona
: Stuart Reges, University of Washington
Version
: 2021/09/28
See also
: http://effbot.org/tkinterbook/canvas.htm

Constructor & Destructor Documentation

◆ __init__()

def DrawingPanel.DrawingPanel.__init__ (   self,
  window,
  width = 500,
  height = 500,
  background = "white",
**  options 
)

Constructs a panel of a given width, height, and optional background color.

Parameters:

Parameters
width(optional) width of the DrawingPanel central canvas area in pixels (default 500)
height(optional) height of the DrawingPanel central canvas area in pixels (default 500)
background(optional) background color of the DrawingPanel canvas area (default "white")
options(optional) keyword arguments to pass directly to Tk window constructor (see Tkinter documentation)

Member Function Documentation

◆ add_key_listener()

def DrawingPanel.DrawingPanel.add_key_listener (   self,
  function,
  event_type = "press" 
)

Attaches the given function to be called when keyboard events occur in this DrawingPanel window.

Parameters
functionThe function to be called; should accept an event as a parameter.
event_type(optional) What type of mouse event to respond to. The default is key presses, but you can pass any of "press" or "release".
See also
: http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm

◆ add_mouse_listener()

def DrawingPanel.DrawingPanel.add_mouse_listener (   self,
  function,
  event_type = "click" 
)

Attaches the given function to be called when mouse events occur in this DrawingPanel window.

Parameters
functionThe function to be called; should accept an event as a parameter.
event_type(optional) What type of mouse event to respond to. The default is clicks, but you can pass any of "click", "doubleclick", "drag", "enter", "exit", "middleclick", "move", "press", "release", "rightclick", or "wheel".
See also
: http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm

◆ background()

def DrawingPanel.DrawingPanel.background (   self)

The panel's background color.

Default is white.

Returns
type str

◆ background_rgb()

def DrawingPanel.DrawingPanel.background_rgb (   self)

The panel's background color as an RGB tuple such as (255, 0, 192).

Default is white.

Returns
type tuple

◆ color() [1/2]

def DrawingPanel.DrawingPanel.color (   self)

The default color used to outline drawn shapes.

This color will be used unless you explicitly pass a color to the drawing function to draw a particular shape. Equivalent to foreground.

Returns
type str

◆ color() [2/2]

def DrawingPanel.DrawingPanel.color (   self,
  value 
)

Sets the color used to outline future drawn shapes.

The color passed must be a color string like "purple" or a hex string like "#ff00ff".

See also
: http://wiki.tcl.tk/16166

◆ draw_arc()

def DrawingPanel.DrawingPanel.draw_arc (   self,
  x,
  y,
  w,
  h,
  start_angle,
  extent,
  color = "",
**  options 
)

Draws an outlined arc (a partial oval).

The resulting arc begins at 'start_angle' and extends for 'extent' degrees. Angles are interpreted such that 0 degrees is at the 3 o'clock position. A positive value indicates a counter-clockwise rotation while a negative value indicates a clockwise rotation.

If you want to draw a pie-slice style arc rather than just the outer line, pass an option of style="pieslice".

Parameters
xleft x coordinate of bounding box of arc's oval
ytop y coordinate of bounding box of arc's oval
wwidth of bounding box of arc's oval
hheight of bounding box of arc's oval
start_anglestarting angle in degrees, where 0 is at "3 o'clock" position
extentdegrees that the arc should extend from its start, where positive numbers are counter-clockwise and negative values are clockwise
color(optional) color to use for outline of shape (if absent, uses panel's default color as set via set_color)
See also
: http://effbot.org/tkinterbook/canvas.htm#Tkinter.Canvas.create_arc-method

◆ draw_image()

def DrawingPanel.DrawingPanel.draw_image (   self,
  filename,
  x = 0,
  y = 0,
  w = 0,
  h = 0,
**  options 
)

Draws an image from a file or Image object with its top-left corner at the given (x, y) pixel.

Due to tkinter limitations, can recognize PNG and GIF but not JPG. Sorry. :-(

Parameters
filenamepath to image file, or Tkinter Image object representing the image to draw @type filename: str or Image
x(optional) top-left x-coordinate at which to place the image; default 0
y(optional) top-left y-coordinate at which to place the image; default 0
w(optional) width at which to draw the image (not yet supported)
h(optional) height at which to draw the image (not yet supported)
options(optional) keyword arguments to pass directly to Tk create_image function (see Tkinter documentation)
Todo:
: support resizing of images (does not work yet)
See also
: http://effbot.org/tkinterbook/canvas.htm#canvas.Canvas.create_image-method

◆ draw_line()

def DrawingPanel.DrawingPanel.draw_line (   self,
  x1,
  y1,
  x2,
  y2,
  color = "",
**  options 
)

Draws a line between the two given points (x1, y1) and (x2, y2).

Parameters
x1starting point's x-coordinate
y1starting point's y-coordinate
x2ending point's x-coordinate
y2ending point's y-coordinate
color(optional) color with which to draw line (if absent, uses panel's default color as set via set_color)
options(optional) keyword arguments to pass directly to Tk create_line function (see Tkinter documentation)
See also
: http://effbot.org/tkinterbook/canvas.htm#Tkinter.Canvas.create_line-method

◆ draw_oval()

def DrawingPanel.DrawingPanel.draw_oval (   self,
  x,
  y,
  w,
  h,
  color = "",
**  options 
)

Draws an oval the given size with its top-left corner at the given (x, y) pixel.

You can pass the outline color as a last positional parameter, or it can be a keyword parameter (in options), or if none is passed at all, we will fall back to the panel's default outline color. The polygon will not be filled unless a 'fill' named parameter is passed.

Parameters
xleft x coordinate of bounding box of oval
ytop y coordinate of bounding box of oval
wwidth of bounding box of oval
hheight of bounding box of oval
color(optional) color to use for outline of shape (if absent, uses panel's default color as set via set_color)
options(optional) keyword arguments to pass directly to Tk create_oval function (see Tkinter documentation)
See also
: http://effbot.org/tkinterbook/canvas.htm#Tkinter.Canvas.create_oval-method

◆ draw_pixel()

def DrawingPanel.DrawingPanel.draw_pixel (   self,
  x,
  y,
  color = "",
**  options 
)

Changes the color at the given (x, y) pixel.

Equivalent to drawing a 1x1 rectangle.

Parameters
xx coordinate
yy coordinate
color(optional) color to use for pixel (if absent, uses panel's default color as set via set_color)
options(optional) keyword arguments to pass directly to Tk create_rectangle function (see Tkinter documentation)
See also
: http://effbot.org/tkinterbook/canvas.htm#Tkinter.Canvas.create_rectangle-method

◆ draw_polygon()

def DrawingPanel.DrawingPanel.draw_polygon (   self,
coords,
**  options 
)

Draws an outlined polygon between the given coordinates passed as individual x/y coordinate parameters or (x,y) tuples.

You can pass the outline color as a last positional parameter, or it can be a keyword parameter (in options), or if none is passed at all, we will fall back to the panel's default outline color. The polygon will not be filled unless a 'fill' named parameter is passed.

example: panel.draw_polygon(x1, y1, x2, y2, x3, y3) example: panel.draw_polygon(x1, y1, x2, y2, x3, y3, x4, y4, "red") example: panel.draw_polygon(p1, p2, p3)

Parameters
coordsx, y coordinate pairs of arbitrary number
options(optional) keyword arguments to pass directly to Tk create_polygon and/or create_line function (see Tkinter documentation)
See also
: http://effbot.org/tkinterbook/canvas.htm#Tkinter.Canvas.create_polygon-method

◆ draw_polyline()

def DrawingPanel.DrawingPanel.draw_polyline (   self,
coords,
**  options 
)

Draws a group of lines between the given coordinates passed as individual x/y coordinate parameters or (x,y) tuples.

You can pass the outline color as a last positional parameter, or it can be a keyword parameter (in options), or if none is passed at all, we will fall back to the panel's default outline color. The difference between draw_polyline and draw_polygon is that the polygon will connect its last line point back to the start point; the polygon can also be filled, while a polyline cannot.

example: panel.draw_polyline(x1, y1, x2, y2, x3, y3) example: panel.draw_polyline(x1, y1, x2, y2, x3, y3, x4, y4, "red") example: panel.draw_polyline(p1, p2, p3)

Parameters
coordsx, y coordinate pairs of arbitrary number
options(optional) keyword arguments to pass directly to Tk create_line function (see Tkinter documentation)
See also
: http://effbot.org/tkinterbook/canvas.htm#Tkinter.Canvas.create_line-method

◆ draw_rect()

def DrawingPanel.DrawingPanel.draw_rect (   self,
  x,
  y,
  w,
  h,
  color = "",
**  options 
)

Draws a rectangle of the given size with its top-left corner at the given (x, y) pixel.

Equivalent to draw_rectangle.

Parameters
xleft x coordinate of bounding box of rectangle
ytop y coordinate of bounding box of rectangle
wwidth of bounding box of rectangle
hheight of bounding box of rectangle
color(optional) color to use for outline of shape (if absent, uses panel's default color as set via set_color)
options(optional) keyword arguments to pass directly to Tk create_rectangle function (see Tkinter documentation)
See also
: http://effbot.org/tkinterbook/canvas.htm#Tkinter.Canvas.create_rectangle-method

◆ draw_rectangle()

def DrawingPanel.DrawingPanel.draw_rectangle (   self,
  x,
  y,
  w,
  h,
  color = "",
**  options 
)

Draws a rectangle of the given size with its top-left corner at the given (x, y) pixel.

Equivalent to draw_rect.

Parameters
xleft x coordinate of bounding box of rectangle
ytop y coordinate of bounding box of rectangle
wwidth of bounding box of rectangle
hheight of bounding box of rectangle
color(optional) color to use for outline of shape (if absent, uses panel's default color as set via set_color)
options(optional) keyword arguments to pass directly to Tk create_rectangle function (see Tkinter documentation)
See also
: http://effbot.org/tkinterbook/canvas.htm#Tkinter.Canvas.create_rectangle-method

◆ draw_string()

def DrawingPanel.DrawingPanel.draw_string (   self,
  text,
  x,
  y,
  color = "",
  font = "",
**  options 
)

Draws a text string with its top-left corner at the given (x, y) pixel.

Parameters
xleft x coordinate of start of text
ytop y coordinate of start of text
color(optional) color to use for outline of shape (if absent, uses panel's default color as set via set_color)
font(optional) font face to use to render text, in "family size style" format, such as "Times New Roman 16 bold italic"
options(optional) keyword arguments to pass directly to Tk create_text function (see Tkinter documentation)
See also
: http://effbot.org/tkinterbook/canvas.htm#Tkinter.Canvas.create_text-method

◆ fill_arc()

def DrawingPanel.DrawingPanel.fill_arc (   self,
  x,
  y,
  w,
  h,
  start_angle,
  extent,
  color = "",
**  options 
)

Draws a filled arc (a partial oval).

The resulting arc begins at 'start_angle' and extends for 'extent' degrees. Angles are interpreted such that 0 degrees is at the 3 o'clock position. A positive value indicates a counter-clockwise rotation while a negative value indicates a clockwise rotation. You can pass the outline color as a named 'outline' parameter, else the fill color will be used as the outline color.

Parameters
xleft x coordinate of bounding box of arc's oval
ytop y coordinate of bounding box of arc's oval
wwidth of bounding box of arc's oval
hheight of bounding box of arc's oval
start_anglestarting angle in degrees, where 0 is at "3 o'clock" position
extentdegrees that the arc should extend from its start, where positive numbers are counter-clockwise and negative values are clockwise
color(optional) color to use for fill of shape (if absent, uses panel's default fill color as set via set_fill_color)
See also
: http://effbot.org/tkinterbook/canvas.htm#Tkinter.Canvas.create_arc-method

◆ fill_color() [1/2]

def DrawingPanel.DrawingPanel.fill_color (   self)

The default color used to fill in shapes.

This color will be used unless you explicitly pass a color to the filling function to draw a particular shape.

Returns
type str

◆ fill_color() [2/2]

def DrawingPanel.DrawingPanel.fill_color (   self,
  value 
)

Sets the color used to fill in future drawn shapes.

The color passed must be a color string like "purple" or a hex string like "#ff00ff".

◆ fill_oval()

def DrawingPanel.DrawingPanel.fill_oval (   self,
  x,
  y,
  w,
  h,
  color = "",
**  options 
)

Draws a filled oval of the given size with its top-left corner at the given (x, y) pixel.

You can pass the fill color as a fifth positional parameter, or it can be a keyword parameter (in options), or if none is passed at all, we will fall back to the panel's default fill color. You can pass the outline color as a named 'outline' parameter, else the fill color will be used as the outline color.

Parameters
xleft x coordinate of bounding box of oval
ytop y coordinate of bounding box of oval
wwidth of bounding box of oval
hheight of bounding box of oval
color(optional) color to use for fill of shape (if absent, uses panel's default color as set via set_fill_color)
options(optional) keyword arguments to pass directly to Tk create_oval function (see Tkinter documentation)
See also
: http://effbot.org/tkinterbook/canvas.htm#Tkinter.Canvas.create_oval-method

◆ fill_polygon()

def DrawingPanel.DrawingPanel.fill_polygon (   self,
coords,
**  options 
)

Draws a filled polygon between the given coordinates passed as individual x/y coordinate parameters or (x,y) tuples.

You can pass the 'fill' as a last positional parameter, or it can be a keyword parameter (in options), or if none is passed at all, we will fall back to the panel's default fill color. You can pass the outline color as a named 'outline' parameter, else the fill color will be used as the outline color.

example: panel.fill_polygon(x1, y1, x2, y2, x3, y3) example: panel.fill_polygon(x1, y1, x2, y2, x3, y3, x4, y4, "red") example: panel.fill_polygon(p1, p2, p3)

Parameters
coordsx, y coordinate pairs of arbitrary number
options(optional) keyword arguments to pass directly to Tk create_polygon function (see Tkinter documentation)
See also
: http://effbot.org/tkinterbook/canvas.htm#Tkinter.Canvas.create_polygon-method

◆ fill_rect()

def DrawingPanel.DrawingPanel.fill_rect (   self,
  x,
  y,
  w,
  h,
  color = "",
**  options 
)

Draws a filled rectangle of the given size with its top-left corner at the given (x, y) pixel.

You can pass the fill color as a fifth positional parameter, or it can be a keyword parameter (in options), or if none is passed at all, we will fall back to the panel's default fill color. You can pass the outline color as a named 'outline' parameter, else the fill color will be used as the outline color. Equivalent to fill_rectangle.

Parameters
xleft x coordinate of bounding box of rectangle
ytop y coordinate of bounding box of rectangle
wwidth of bounding box of rectangle
hheight of bounding box of rectangle
color(optional) color to use to fill shape (if absent, uses panel's default color as set via set_fill_color)
options(optional) keyword arguments to pass directly to Tk create_rectangle function (see Tkinter documentation)
See also
: http://effbot.org/tkinterbook/canvas.htm#Tkinter.Canvas.create_rectangle-method

◆ fill_rectangle()

def DrawingPanel.DrawingPanel.fill_rectangle (   self,
  x,
  y,
  w,
  h,
  fill = "",
  color = "",
**  options 
)

Draws a filled rectangle of the given size with its top-left corner at the given (x, y) pixel.

Equivalent to fill_rect.

Parameters
xleft x coordinate of bounding box of rectangle
ytop y coordinate of bounding box of rectangle
wwidth of bounding box of rectangle
hheight of bounding box of rectangle
color(optional) color to use to fill shape (if absent, uses panel's default color as set via set_fill_color)
options(optional) keyword arguments to pass directly to Tk create_rectangle function (see Tkinter documentation)
See also
: http://effbot.org/tkinterbook/canvas.htm#Tkinter.Canvas.create_rectangle-method

◆ font() [1/2]

def DrawingPanel.DrawingPanel.font (   self)

The font used for drawn strings.

Pass a string in "FONTNAME SIZE STYLE" format, with the last two tokens optional, such as "Helvetica" or "Consolas 14" or "Times New Roman 16 bold".

Returns
type str
See also
: http://effbot.org/tkinterbook/tkinter-widget-styling.htm

◆ font() [2/2]

def DrawingPanel.DrawingPanel.font (   self,
  value 
)

Sets the font used for future drawn strings.

Pass a string in "FONTNAME SIZE STYLE" format, with the last two tokens optional, such as "Helvetica" or "Consolas 14" or "Times New Roman 16 bold".

See also
: http://effbot.org/tkinterbook/tkinter-widget-styling.htm

◆ foreground() [1/2]

def DrawingPanel.DrawingPanel.foreground (   self)

The default color used to outline drawn shapes.

This color will be used unless you explicitly pass a color to the drawing function to draw a particular shape. Equivalent to color.

Returns
type str

◆ foreground() [2/2]

def DrawingPanel.DrawingPanel.foreground (   self,
  value 
)

Sets the color used to outline and fill future drawn shapes.

The color passed must be a color string like "purple" or a hex string like "#ff00ff". Equivalent to setting color.

◆ get_background()

def DrawingPanel.DrawingPanel.get_background (   self)

Returns the panel's background color.

Default is white.

Returns
str color as hex string such as "#ff00cc"
type str

◆ get_background_rgb()

def DrawingPanel.DrawingPanel.get_background_rgb (   self)

Returns the panel's background color as an RGB tuple.

Default is white.

Returns
: color as a 3-element rgb tuple such as (255, 0, 192)
type tuple

◆ get_color()

def DrawingPanel.DrawingPanel.get_color (   self)

Returns the default color used to outline drawn shapes.

This color will be used unless you explicitly pass a color to the drawing function to draw a particular shape. Equivalent to get_foreground.

Returns
type str

◆ get_fill_color()

def DrawingPanel.DrawingPanel.get_fill_color (   self)

Returns the default color used to fill in shapes.

This color will be used unless you explicitly pass a color to the filling function to draw a particular shape.

Returns
type str

◆ get_font()

def DrawingPanel.DrawingPanel.get_font (   self)

Returns the font used for drawn strings.

Pass a string in "FONTNAME SIZE STYLE" format, with the last two tokens optional, such as "Helvetica" or "Consolas 14" or "Times New Roman 16 bold".

Returns
: font as a "family size style" string such as "Times New Roman 16 bold italic"
type str
See also
: http://effbot.org/tkinterbook/tkinter-widget-styling.htm

◆ get_foreground()

def DrawingPanel.DrawingPanel.get_foreground (   self)

Returns the default color used to outline drawn shapes.

This color will be used unless you explicitly pass a color to the drawing function to draw a particular shape. Equivalent to get_color.

Returns
type str

◆ get_height()

def DrawingPanel.DrawingPanel.get_height (   self)

Returns the height of the panel's canvas area.

Returns
: height in pixels as an int
type int

◆ get_outline_color()

def DrawingPanel.DrawingPanel.get_outline_color (   self)

Returns the default color used to outline drawn shapes.

This color will be used unless you explicitly pass a color to the drawing function to draw a particular shape. Equivalent to get_color.

Returns
type str

◆ get_pixel()

def DrawingPanel.DrawingPanel.get_pixel (   self,
  x,
  y 
)

Returns the RGB color of the given (x, y) pixel on the canvas as a 3-tuple of three integers from 0-255 representing the Red, Green, and Blue components.

NOTE: This function currently fails when there are text strings drawn onto the canvas. It interprets every pixel in the bounding box of the text string to be the text string's color. Equivalent to get_pixel_color_rgb.

Parameters
xx coordinate of pixel
yy coordinate of pixel
Returns
type tuple

◆ get_pixel_color()

def DrawingPanel.DrawingPanel.get_pixel_color (   self,
  x,
  y 
)

Returns the RGB color of the given (x, y) pixel on the canvas as a string such as "#ff00ff".

NOTE: This function currently fails when there are text strings drawn onto the canvas. It interprets every pixel in the bounding box of the text string to be the text string's color.

Parameters
xx coordinate of pixel
yy coordinate of pixel
Returns
type str

◆ get_pixel_color_rgb()

def DrawingPanel.DrawingPanel.get_pixel_color_rgb (   self,
  x,
  y 
)

Returns the RGB color of the given (x, y) pixel on the canvas as a 3-tuple of three integers from 0-255 representing the Red, Green, and Blue components.

NOTE: This function currently fails when there are text strings drawn onto the canvas. It interprets every pixel in the bounding box of the text string to be the text string's color.

Parameters
xx coordinate of pixel
yy coordinate of pixel
Returns
type tuple

◆ get_pixel_colors()

def DrawingPanel.DrawingPanel.get_pixel_colors (   self)

Returns a 2D list storing the RGB colors of every pixel on the canvas as a string such as "#ff00ff".

The x-dimension is the first index and the y-dimension is the second index; for example, pixels[x][y] is the RGB color of the pixel at position (x, y).

Returns
type list

◆ get_pixels()

def DrawingPanel.DrawingPanel.get_pixels (   self)

Returns a 2D list storing the RGB colors of every pixel on the canvas as a 3-tuple of three integers from 0-255 representing the Red, Green, and Blue components.

The x-dimension is the first index and the y-dimension is the second index; for example, pixels[x][y] is the RGB color of the pixel at position (x, y).

Returns
type list

◆ get_size()

def DrawingPanel.DrawingPanel.get_size (   self)

Returns a 2-element tuple of the width and height of the panel's canvas area.

Returns
: 2-element tuple such as (400, 300)
type tuple

◆ get_stroke()

def DrawingPanel.DrawingPanel.get_stroke (   self)

Returns the width that will be used to draw lines on future shapes.

Equivalent to get_stroke_width.

Returns
: stroke width (default 1)
type int

◆ get_stroke_width()

def DrawingPanel.DrawingPanel.get_stroke_width (   self)

Returns the width that will be used to draw lines on future shapes.

Equivalent to get_stroke.

Returns
: stroke width (default 1)
type int

◆ get_width()

def DrawingPanel.DrawingPanel.get_width (   self)

Returns the width of the panel's canvas area.

Returns
type int

◆ height()

def DrawingPanel.DrawingPanel.height (   self)

The height of the panel's canvas area.

Returns
type int

◆ outline_color() [1/2]

def DrawingPanel.DrawingPanel.outline_color (   self)

The default color used to outline drawn shapes.

This color will be used unless you explicitly pass a color to the drawing function to draw a particular shape. Equivalent to color.

Returns
type str

◆ outline_color() [2/2]

def DrawingPanel.DrawingPanel.outline_color (   self,
  value 
)

Sets the color used to outline future drawn shapes.

Equivalent to setting color. Pass either a color string such as "yellow" or "#ff00cc"

◆ pack()

def DrawingPanel.DrawingPanel.pack (   self,
  padding_top = 0,
  padding_right = 0,
  padding_bottom = 0,
  padding_left = 0,
  side = '' 
)

Adds this canvas to the frame in the left, or right if side is specified.

example: panel.pack() example: panel.pack(5, 0, 0, 5, "left")

Parameters
padding_topthe amount of extra space between this component and the top
padding_rightthe amount of extra space between this component and the right edge
padding_bottomthe amount of extra space between this component and the bottom
padding_leftthe amount of extra space between this component and the left edge
sidethe side of the GUI this component should be added to

◆ pixel_colors() [1/2]

def DrawingPanel.DrawingPanel.pixel_colors (   self)

A 2D list storing the RGB colors of every pixel on the canvas as strings such as "#ff00ff".

The x-dimension is the first index and the y-dimension is the second index; for example, pixels[x][y] is the RGB color of the pixel at position (x, y).

Returns
type list

◆ pixel_colors() [2/2]

def DrawingPanel.DrawingPanel.pixel_colors (   self,
  px 
)

Sets the RGB values of all pixels in this panel's canvas based on the values in the given 2D list.

Pass a 2D list of strings such as "#ff00ff" with the x-dimension as the first index and the y-dimension as the second index.

◆ pixels() [1/2]

def DrawingPanel.DrawingPanel.pixels (   self)

A 2D list storing the RGB colors of every pixel on the canvas as a 3-tuple of three integers from 0-255 representing the Red, Green, and Blue components.

The x-dimension is the first index and the y-dimension is the second index; for example, pixels[x][y] is the RGB color of the pixel at position (x, y).

Returns
type list

◆ pixels() [2/2]

def DrawingPanel.DrawingPanel.pixels (   self,
  px 
)

Sets the RGB values of all pixels in this panel's canvas based on the values in the given 2D list.

Equivalent to set_pixels. Pass a 2D list of (r, g, b) tuples with the x-dimension as the first index and the y-dimension as the second index.

◆ set_background()

def DrawingPanel.DrawingPanel.set_background (   self,
args 
)

Sets the panel's background color to be the given color.

color – the color to set, as a string such as "yellow" or "black"

Parameters
argseither a color string such as "yellow" or "#ff00cc", or a 3-element RGB tuple such as (255, 0, 192)

◆ set_color()

def DrawingPanel.DrawingPanel.set_color (   self,
args 
)

Sets the color used to outline future drawn shapes.

The color passed can be a color string like "purple" or a hex string like "#ff00ff" or an RGB tuple like (255, 0, 255).

Parameters
argseither a color string such as "yellow" or "#ff00cc", or a 3-element RGB tuple such as (255, 0, 192)
See also
: http://wiki.tcl.tk/16166

◆ set_fill_color()

def DrawingPanel.DrawingPanel.set_fill_color (   self,
args 
)

Sets the color used to fill in future drawn shapes.

The color passed can be a color string like "purple" or a hex string like "#ff00ff" or an RGB tuple like (255, 0, 255).

Parameters
argseither a color string such as "yellow" or "#ff00cc", or a 3-element RGB tuple such as (255, 0, 192)

◆ set_font()

def DrawingPanel.DrawingPanel.set_font (   self,
  font 
)

Sets the font used for future drawn strings.

Pass a string in "FONTNAME SIZE STYLE" format, with the last two tokens optional, such as "Helvetica" or "Consolas 14" or "Times New Roman 16 bold".

Parameters
fonta font string in "FONTNAME SIZE STYLE" format, with the last two tokens optional, such as "Helvetica" or "Consolas 14" or "Times New Roman 16 bold".
See also
: http://effbot.org/tkinterbook/tkinter-widget-styling.htm

◆ set_foreground()

def DrawingPanel.DrawingPanel.set_foreground (   self,
args 
)

Sets the color used to outline and fill future drawn shapes.

The color passed can be a color string like "purple" or a hex string like "#ff00ff" or an RGB tuple like (255, 0, 255). Equivalent to set_color.

Parameters
argseither a color string such as "yellow" or "#ff00cc", or a 3-element RGB tuple such as (255, 0, 192)

◆ set_outline_color()

def DrawingPanel.DrawingPanel.set_outline_color (   self,
args 
)

Sets the color used to outline future drawn shapes.

Equivalent to set_color.

Parameters
argseither a color string such as "yellow" or "#ff00cc", or a 3-element RGB tuple such as (255, 0, 192)

◆ set_pixel()

def DrawingPanel.DrawingPanel.set_pixel (   self,
  x,
  y,
  color = "",
**  options 
)

Changes the color at the given (x, y) pixel.

Equivalent to drawing a 1x1 rectangle, or equivalent to draw_pixel.

Parameters
xx coordinate
yy coordinate
color(optional) color to use for pixel (if absent, uses panel's default color as set via set_color)
options(optional) keyword arguments to pass directly to Tk create_rectangle function (see Tkinter documentation)
See also
: http://effbot.org/tkinterbook/canvas.htm#Tkinter.Canvas.create_rectangle-method

◆ set_pixel_colors()

def DrawingPanel.DrawingPanel.set_pixel_colors (   self,
  pixels 
)

Sets the RGB values of all pixels in this panel's canvas based on the values in the given 2D list.

Pass a 2D list of strings such as "#ff00ff" with the x-dimension as the first index and the y-dimension as the second index.

◆ set_pixels()

def DrawingPanel.DrawingPanel.set_pixels (   self,
  pixels 
)

Sets the RGB values of all pixels in this panel's canvas based on the values in the given 2D list.

Pass a 2D list of (r, g, b) tuples with the x-dimension as the first index and the y-dimension as the second index.

◆ set_stroke()

def DrawingPanel.DrawingPanel.set_stroke (   self,
  width 
)

Sets the width that will be used to draw lines on future shapes.

Equivalent to set_stroke_width.

◆ set_stroke_width()

def DrawingPanel.DrawingPanel.set_stroke_width (   self,
  width 
)

Sets the width that will be used to draw lines on future shapes.

Equivalent to set_stroke.

◆ size()

def DrawingPanel.DrawingPanel.size (   self)

A 2-element tuple of the width and height of the panel's canvas area.

Returns
type tuple

◆ sleep()

def DrawingPanel.DrawingPanel.sleep (   self,
  ms 
)

Causes the DrawingPanel to pause for the given number of milliseconds.

Useful for creating simple animations.

Parameters
msnumber of milliseconds to pause

◆ stroke() [1/2]

def DrawingPanel.DrawingPanel.stroke (   self)

The width that will be used to draw lines on future shapes.

Equivalent to stroke_width.

Returns
type int

◆ stroke() [2/2]

def DrawingPanel.DrawingPanel.stroke (   self,
  width 
)

Sets the width that will be used to draw lines on future shapes.

Equivalent to setting stroke_width.

◆ stroke_width() [1/2]

def DrawingPanel.DrawingPanel.stroke_width (   self)

The width that will be used to draw lines on future shapes.

Equivalent to stroke.

Returns
type int

◆ stroke_width() [2/2]

def DrawingPanel.DrawingPanel.stroke_width (   self,
  width 
)

Sets the width that will be used to draw lines on future shapes.

Equivalent to set_stroke.

◆ width()

def DrawingPanel.DrawingPanel.width (   self)

The width of the panel's canvas area.

Returns
type int

The documentation for this class was generated from the following file: