My Project
|
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... | |
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.
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:
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) |
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.
function | The 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". |
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.
function | The 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". |
def DrawingPanel.DrawingPanel.background | ( | self | ) |
The panel's background color.
Default is white.
def DrawingPanel.DrawingPanel.background_rgb | ( | self | ) |
The panel's background color as an RGB tuple such as (255, 0, 192).
Default is white.
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.
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".
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".
x | left x coordinate of bounding box of arc's oval |
y | top y coordinate of bounding box of arc's oval |
w | width of bounding box of arc's oval |
h | height of bounding box of arc's oval |
start_angle | starting angle in degrees, where 0 is at "3 o'clock" position |
extent | degrees 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) |
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. :-(
filename | path 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) |
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).
x1 | starting point's x-coordinate |
y1 | starting point's y-coordinate |
x2 | ending point's x-coordinate |
y2 | ending 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) |
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.
x | left x coordinate of bounding box of oval |
y | top y coordinate of bounding box of oval |
w | width of bounding box of oval |
h | height 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) |
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.
x | x coordinate |
y | y 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) |
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)
coords | x, 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) |
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)
coords | x, y coordinate pairs of arbitrary number |
options | (optional) keyword arguments to pass directly to Tk create_line function (see Tkinter documentation) |
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.
x | left x coordinate of bounding box of rectangle |
y | top y coordinate of bounding box of rectangle |
w | width of bounding box of rectangle |
h | height 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) |
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.
x | left x coordinate of bounding box of rectangle |
y | top y coordinate of bounding box of rectangle |
w | width of bounding box of rectangle |
h | height 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) |
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.
x | left x coordinate of start of text |
y | top 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) |
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.
x | left x coordinate of bounding box of arc's oval |
y | top y coordinate of bounding box of arc's oval |
w | width of bounding box of arc's oval |
h | height of bounding box of arc's oval |
start_angle | starting angle in degrees, where 0 is at "3 o'clock" position |
extent | degrees 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) |
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.
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".
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.
x | left x coordinate of bounding box of oval |
y | top y coordinate of bounding box of oval |
w | width of bounding box of oval |
h | height 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) |
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)
coords | x, y coordinate pairs of arbitrary number |
options | (optional) keyword arguments to pass directly to Tk create_polygon function (see Tkinter documentation) |
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.
x | left x coordinate of bounding box of rectangle |
y | top y coordinate of bounding box of rectangle |
w | width of bounding box of rectangle |
h | height 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) |
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.
x | left x coordinate of bounding box of rectangle |
y | top y coordinate of bounding box of rectangle |
w | width of bounding box of rectangle |
h | height 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) |
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".
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".
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.
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.
def DrawingPanel.DrawingPanel.get_background | ( | self | ) |
Returns the panel's background color.
Default is white.
def DrawingPanel.DrawingPanel.get_background_rgb | ( | self | ) |
Returns the panel's background color as an RGB tuple.
Default is white.
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.
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.
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".
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.
def DrawingPanel.DrawingPanel.get_height | ( | self | ) |
Returns the height of the panel's canvas area.
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.
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.
x | x coordinate of pixel |
y | y coordinate of pixel |
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.
x | x coordinate of pixel |
y | y coordinate of pixel |
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.
x | x coordinate of pixel |
y | y coordinate of pixel |
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).
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).
def DrawingPanel.DrawingPanel.get_size | ( | self | ) |
Returns a 2-element tuple of the width and height of the panel's canvas area.
def DrawingPanel.DrawingPanel.get_stroke | ( | self | ) |
Returns the width that will be used to draw lines on future shapes.
Equivalent to 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.
def DrawingPanel.DrawingPanel.get_width | ( | self | ) |
Returns the width of the panel's canvas area.
def DrawingPanel.DrawingPanel.height | ( | self | ) |
The height of the panel's canvas area.
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.
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"
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")
padding_top | the amount of extra space between this component and the top |
padding_right | the amount of extra space between this component and the right edge |
padding_bottom | the amount of extra space between this component and the bottom |
padding_left | the amount of extra space between this component and the left edge |
side | the side of the GUI this component should be added to |
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).
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.
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).
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.
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"
args | either a color string such as "yellow" or "#ff00cc", or a 3-element RGB tuple such as (255, 0, 192) |
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).
args | either a color string such as "yellow" or "#ff00cc", or a 3-element RGB tuple such as (255, 0, 192) |
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).
args | either a color string such as "yellow" or "#ff00cc", or a 3-element RGB tuple such as (255, 0, 192) |
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".
font | a 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". |
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.
args | either a color string such as "yellow" or "#ff00cc", or a 3-element RGB tuple such as (255, 0, 192) |
def DrawingPanel.DrawingPanel.set_outline_color | ( | self, | |
* | args | ||
) |
Sets the color used to outline future drawn shapes.
Equivalent to set_color.
args | either a color string such as "yellow" or "#ff00cc", or a 3-element RGB tuple such as (255, 0, 192) |
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.
x | x coordinate |
y | y 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) |
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.
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.
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.
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.
def DrawingPanel.DrawingPanel.size | ( | self | ) |
A 2-element tuple of the width and height of the panel's canvas area.
def DrawingPanel.DrawingPanel.sleep | ( | self, | |
ms | |||
) |
Causes the DrawingPanel to pause for the given number of milliseconds.
Useful for creating simple animations.
ms | number of milliseconds to pause |
def DrawingPanel.DrawingPanel.stroke | ( | self | ) |
The width that will be used to draw lines on future shapes.
Equivalent to stroke_width.
def DrawingPanel.DrawingPanel.stroke | ( | self, | |
width | |||
) |
Sets the width that will be used to draw lines on future shapes.
Equivalent to setting stroke_width.
def DrawingPanel.DrawingPanel.stroke_width | ( | self | ) |
The width that will be used to draw lines on future shapes.
Equivalent to stroke.
def DrawingPanel.DrawingPanel.stroke_width | ( | self, | |
width | |||
) |
Sets the width that will be used to draw lines on future shapes.
Equivalent to set_stroke.
def DrawingPanel.DrawingPanel.width | ( | self | ) |
The width of the panel's canvas area.