python tkinter canvas code example

Example 1: rectangle in tkinter

from tkinter import *

root = Tk()

c = Canvas(root)
c.pack()
c.create_rectangle(100, 100, 200, 200)

root.mainloop()

Example 2: tkinter create_line

canvas.create_line(15, 25, 200, 25)

Example 3: how to draw polygon in tkinter

from tkinter import *

root = Tk()

c = Canvas(root)
c.pack()

points = [x1,y1, x2,y2, xn,yn]
c.create_polygon(points)

root.mainloop()

Example 4: canvas.create_oval parameters

id = C.create_oval ( x0, y0, x1, y1, option, ... )