Home | Trees | Indices | Help |
---|
|
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.
Version: 2018/02/28
Copyright: Marty Stepp, Allison Obourn, Stuart Reges; for individual, educational, non-commercial, private use only; all other rights reserved.
See Also: http://effbot.org/tkinterbook/canvas.htm
Instance Methods | |||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
str |
|
||
tuple |
|
||
str |
|
||
str |
|
||
str |
|
||
str |
|
||
int |
|
||
tuple |
|
||
str |
|
||
str |
|
||
str |
|
||
tuple |
|
||
int |
|
||
str |
|
||
int |
|
||
int |
|
||
Tk |
|
||
tuple |
|
||
int |
|
||
int |
|
||
|
|||
bool |
|
||
bool |
|
||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
Properties | |
tuple |
background_rgb The panel's background color as an RGB tuple such as (255, 0, 192). |
Tk |
window The underlying Tkinter window being displayed on the screen. |
tuple |
window_size A 2-element tuple of the width and height of the panel's entire window including borders and status bar. |
str |
background The panel's background color. |
str |
color The default color used to outline drawn shapes. |
str |
fill_color The default color used to fill in shapes. |
str |
font The font used for drawn strings. |
str |
foreground The default color used to outline drawn shapes. |
int |
height The height of the panel's canvas area. |
tuple |
location A 2-element tuple containing the panel's window's top-left x/y corner. |
str |
outline_color The default color used to outline drawn shapes. |
bool |
resizable Whether the DrawingPanel window is able to be resized; initially True. |
tuple |
size A 2-element tuple of the width and height of the panel's canvas area. |
int |
stroke The width that will be used to draw lines on future shapes. |
int |
stroke_width The width that will be used to draw lines on future shapes. |
str |
title The window title bar text. |
bool |
visible Whether the DrawingPanel window is visible on the screen. |
int |
width The width of the panel's canvas area. |
int |
x The panel's window's left x pixel position. |
int |
y The panel's window's top y pixel position. |
Method Details |
Constructs a panel of a given width, height, and optional background color. Parameters:
|
Attaches the given function to be called when keyboard events occur in this DrawingPanel window.
See Also: http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm |
Attaches the given function to be called when mouse events occur in this DrawingPanel window.
See Also: http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm |
Centers the DrawingPanel window's location on the screen. If the DrawingPanel's size is larger than the screen size in either dimension, does not move it. |
Closes the DrawingPanel window so it is no longer visible. Once it is closed, it cannot be drawn on or shown on screen again during the current run of your program. |
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".
See Also: http://effbot.org/tkinterbook/canvas.htm#Tkinter.Canvas.create_arc-method |
Draws an image from a file with its top-left corner at the given (x, y) pixel. Due to tkinter limitations, can recognize PNG and GIF but not JPG. Sorry. :-(
To Do: support resizing of images (does not work yet) See Also: http://effbot.org/tkinterbook/canvas.htm#canvas.Canvas.create_image-method |
Draws a line between the two given points (x1, y1) and (x2, y2).
See Also: http://effbot.org/tkinterbook/canvas.htm#Tkinter.Canvas.create_line-method |
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.
See Also: http://effbot.org/tkinterbook/canvas.htm#Tkinter.Canvas.create_oval-method |
Changes the color at the given (x, y) pixel. Equivalent to drawing a 1x1 rectangle.
See Also: http://effbot.org/tkinterbook/canvas.htm#Tkinter.Canvas.create_rectangle-method |
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)
See Also: http://effbot.org/tkinterbook/canvas.htm#Tkinter.Canvas.create_line-method |
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)
See Also: http://effbot.org/tkinterbook/canvas.htm#Tkinter.Canvas.create_polygon-method |
Draws a rectangle of the given size with its top-left corner at the given (x, y) pixel. Equivalent to draw_rectangle.
See Also: http://effbot.org/tkinterbook/canvas.htm#Tkinter.Canvas.create_rectangle-method |
Draws a rectangle of the given size with its top-left corner at the given (x, y) pixel. Equivalent to draw_rect.
See Also: http://effbot.org/tkinterbook/canvas.htm#Tkinter.Canvas.create_rectangle-method |
Draws a text string with its top-left corner at the given (x, y) pixel.
See Also: http://effbot.org/tkinterbook/canvas.htm#Tkinter.Canvas.create_text-method |
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.
See Also: http://effbot.org/tkinterbook/canvas.htm#Tkinter.Canvas.create_arc-method |
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.
See Also: http://effbot.org/tkinterbook/canvas.htm#Tkinter.Canvas.create_oval-method |
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)
See Also: http://effbot.org/tkinterbook/canvas.htm#Tkinter.Canvas.create_polygon-method |
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.
See Also: http://effbot.org/tkinterbook/canvas.htm#Tkinter.Canvas.create_rectangle-method |
Draws a filled rectangle of the given size with its top-left corner at the given (x, y) pixel. Equivalent to fill_rect.
See Also: http://effbot.org/tkinterbook/canvas.htm#Tkinter.Canvas.create_rectangle-method |
Returns the panel's background color. Default is white.
|
Returns the panel's background color as an RGB tuple. Default is white.
|
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 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 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".
See Also: http://effbot.org/tkinterbook/tkinter-widget-styling.htm |
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 the height of the panel's canvas area.
|
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 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.
|
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.
|
Returns a 2-element tuple of the width and height of the panel's canvas area.
|
Returns the width that will be used to draw lines on future shapes. Equivalent to get_stroke_width.
|
Returns the window title bar text.
|
Returns the width that will be used to draw lines on future shapes. Equivalent to get_stroke.
|
Returns a 2-element tuple of the width and height of the panel's entire window including borders and status bar.
|
Returns whether the DrawingPanel window is able to be resized; initially True.
|
Returns whether the DrawingPanel window is visible on the screen. If the DrawingPanel has been closed or hidden, returns False.
|
Pops up a question message box displaying the given text with Yes/No buttons. If user presses Yes, returns True; if No, returns False. |
Saves the drawing panel to the given output file. Formats supported: .ppm, .ps 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.
To Do: use PIL library to save if lib is present |
Sets the panel's background color to be the given color. color -- the color to set, as a string such as "yellow" or "black"
|
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).
See Also: http://wiki.tcl.tk/16166 |
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).
|
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 |
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.
|
Sets the panel's canvas height to the given value.
|
Sets the window's location such that its top-left corner is at the given x/y pixel position.
|
Sets the color used to outline future drawn shapes. Equivalent to set_color.
|
Sets whether the DrawingPanel window is able to be resized; initially True.
|
Sets the window's size such that its canvas will be the given width and height.
|
Sets the width that will be used to draw lines on future shapes. Equivalent to set_stroke_width. |
Sets the width that will be used to draw lines on future shapes. Equivalent to set_stroke. |
Sets the panel's window's left x pixel position to the given value.
|
Sets the panel's window's top y pixel position to the given value.
|
Causes the DrawingPanel to pause for the given number of milliseconds. Useful for creating simple animations.
|
Property Details |
background_rgbThe panel's background color as an RGB tuple such as (255, 0, 192). Default is white.
|
windowThe underlying Tkinter window being displayed on the screen.
|
window_sizeA 2-element tuple of the width and height of the panel's entire window including borders and status bar.
|
backgroundThe panel's background color. Default is white.
|
colorThe 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.
|
fill_colorThe 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.
|
fontThe 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".
See Also: http://effbot.org/tkinterbook/tkinter-widget-styling.htm |
foregroundThe 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.
|
heightThe height of the panel's canvas area.
|
locationA 2-element tuple containing the panel's window's top-left x/y corner.
|
outline_colorThe 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.
|
resizableWhether the DrawingPanel window is able to be resized; initially True.
|
sizeA 2-element tuple of the width and height of the panel's canvas area.
|
strokeThe width that will be used to draw lines on future shapes. Equivalent to stroke_width.
|
stroke_widthThe width that will be used to draw lines on future shapes. Equivalent to stroke.
|
titleThe window title bar text.
|
visibleWhether the DrawingPanel window is visible on the screen. If the DrawingPanel has been closed or hidden, returns False.
|
widthThe width of the panel's canvas area.
|
xThe panel's window's left x pixel position.
|
yThe panel's window's top y pixel position.
|
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Thu Mar 1 18:59:08 2018 | http://epydoc.sourceforge.net |