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-
- import tkinter
- main= tkinter.Tk()
- C =tkinter.Canvas(main, bg="yellow", height=300, width=300)
- coord = 10, 50, 240, 210
- arc = C.create_arc(coord, start=0, extent=150, fill="blue")
- C.pack()
- main.mainloop()
Output-
Option | Description |
bd | Sets border width in pixels. Default is 2. |
bg | Sets 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. |
yscrollincrement | Used 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.