Tkinter Widgets-Canvas

The canvas is a rectangular area intended for drawing. We can place the graphics, text, on a Canvas very easily.

Syntax-

w = Canvas ( main, option=value, ... )
Main-parent window.
Option-attribute of button widget.

Example-
  1. import tkinter  
  2. main= tkinter.Tk()  
  3. C =tkinter.Canvas(main, bg="yellow", height=300, width=300)  
  4. coord = 1050240210  
  5. arc = C.create_arc(coord, start=0, extent=150, fill="blue")  
  6. C.pack()  
  7. main.mainloop()  
Output-
 
Option Description
bdSets border width in pixels. Default is 2.
bgSets Normal background color.
confine
If true (the default), the canvas cannot be scrolled outside of the scroll region.
cursor Cursor is used to have cursor in canvas like arrow, circle, dot etc.
height
 Sets height of the canvas.
highlightcolor

Sets color of widget on focus.
relief
Relief is a special type of the border. The values are SUNKEN, RAISED, GROOVE, and RIDGE.
Scrollregion
Used to create a scrollregion.
width
Used to set the width of widgets
xscrollincrement
Used to define the scrolling value is x direction.
xscrollcommand
 Used to scroll on defining the value in x direction.
yscrollincrementUsed to define the scrolling value is y direction.
yscrollcommand
Used to define the scrolling value is y direction.

Summary

In this chapter, you learnt what canvas widget is and how to use the property of the widget.
Next » Tkinter Widget-Entry