Python

Python Tkinter Canvas: A Guide to Structured Graphics in Python

Python Tkinter Canvas
Python Tkinter Canvas

Python Tkinter Canvas: Complete Guide

The Canvas widget in Tkinter is a powerful tool for adding graphics, shapes, and drawings to Python GUI applications. Use it to build charts, graphs, games, and custom drawing tools.

Complete Python Course:-
Complete Advance AI topics:-

Syntax

canvas = Canvas(parent, options)

Where parent is the parent window or frame and options are configuration attributes.

Common Canvas Options

  • bd ÔÇö border width (default 2)
  • bg ÔÇö background color
  • width / height ÔÇö canvas dimensions
  • cursor ÔÇö cursor type (arrow, circle, dot)
  • relief ÔÇö border style (SUNKEN, RAISED, GROOVE)
  • scrollregion ÔÇö scrollable area (x1, y1, x2, y2)
  • xscrollcommand / yscrollcommand ÔÇö attach scrollbars

Example 1: Basic Canvas

from tkinter import *

top = Tk()
top.geometry("200x200")

c = Canvas(top, bg="pink", height=200, width=200)
c.pack()

top.mainloop()

Example 2: Draw an Arc

from tkinter import *

top = Tk()
top.geometry("200x200")

c = Canvas(top, bg="pink", height=200, width=200)
c.create_arc((5, 10, 150, 200), start=0, extent=150, fill="white")
c.pack()

top.mainloop()

More Drawing Methods

  • create_line(x1, y1, x2, y2) ÔÇö straight line
  • create_rectangle(x1, y1, x2, y2) ÔÇö rectangle
  • create_oval(x1, y1, x2, y2) ÔÇö oval/circle
  • create_polygon(points) ÔÇö polygon
  • create_text(x, y, text="Hello") ÔÇö text
  • create_image(x, y, image=img) ÔÇö image

Quick Multi-Shape Demo

from tkinter import *

root = Tk()
c = Canvas(root, width=300, height=200, bg="white")
c.create_rectangle(10, 10, 100, 80, fill="lightblue")
c.create_oval(120, 10, 200, 80, fill="lightgreen")
c.create_line(0, 100, 300, 100, fill="red", width=3)
c.create_text(150, 150, text="UpdateGadh!", font=("Arial", 14))
c.pack()
root.mainloop()

Download New Real Time Projects:- Click here

Conclusion

The Tkinter Canvas widget is incredibly versatile ÔÇö perfect for charts, games, drawing apps, and custom UI elements. Master the basic shapes and event binding, and you can build rich GUI applications. For more tutorials, stay tuned to .

python tkinter canvas documentation
python tkinter canvas create_text
python tkinter canvas methods
python tkinter canvas image
python tkinter canvas example
tkinter canvas create rectangle
tkinter canvas size
python tkinter label

Source Code Available

Interested in This Project?

Get the complete source code for this project at a very affordable price — perfect for your portfolio, college submission, or learning. Message us on WhatsApp and we'll get back to you instantly!

Full source code included Step-by-step setup guide Instant delivery on WhatsApp Instant reply on WhatsApp
Chat on WhatsApp

We usually reply within a few minutes

Leave a Reply

Your email address will not be published. Required fields are marked *

Chat with us