| Widgets/Canvas |
UserPreferences |
| Tkinter Wiki | FrontPage | RecentChanges | TitleIndex | WordIndex | SiteNavigation | HelpContents | moin.sf.net |
A canvas is a versatile widget that can display multiple graphics and text "items" within its boundaries. Each item can be manipulated and formatted separately.
Items that can be placed on a Canvas widget include arc, bitmap, image, line, oval, polygon, rectangle, text, and widget. Use arc, line, oval, polygon, and rectangle items to draw your own graphics on the canvas. Use bitmap and image (gif images are supported but for other formats the Python Imaging Library is required) to import graphics. Use text to place text items or labels anywhere on the canvas (each text item can have its own font, color, and other attributes set independently). Use a window item to hold other Tkinter widgets.
Each item on a Canvas can be given one or more tags. It is sometimes useful to give an item multiple tags as a way of grouping items for later operations. You can specify the tags either as a tuple (not a list) of strings, or as a single string with the tags separated by whitespace.
Canvas items are not Python objects; they are only accessible through the methods of the Canvas object. The "handle" that is returned when you create an item is simply an integer that the Canvas uses to identify the item.
The Canvas module (not Tkinter.Canvas) allows you to create canvas items that are wrapped by Python objects. However, a comment at the top of this file notes that it is considered obsolete.
If you create a canvas without scrollbars, the origin might be hidden by the Canvas border. ?FredrikLundh says:
by default, the coordinate system is aligned with the widget's upper
left corner, which means that things you draw will be covered by the
inner border.
to fix this, you can either set the border width to zero, add scrollbars
to the widget (this fixes the coordinate system), or explicitly reset the
coordinate system:
w.xview_moveto(0)
w.yview_moveto(0)
http://www.pythonware.com/library/tkinter/introduction/canvas.htm
http://www.purl.org/tcl/home/man/tcl8.4/TkCmd/canvas.htm