0
568views
Write a python program to create different shapes using Canvas class using Python Tkinter
1 Answer
0
2views


To draw a line :-

import tkinter as tk
from tkinter import Canvas

app = tk.Tk()
app.title("Canvas")

canvas = Canvas(app)
canvas.pack()

canvas.create_line(10, 10, 150, 50)

app.mainloop()


Output :-

enter image description here




To draw a Rectangle :-

import tkinter as tk
from tkinter import Canvas

app = tk.Tk()
app.title("Canvas")

canvas = Canvas(app)
canvas.pack()

canvas.create_rectangle(20, 20, 100, 100)

app.mainloop()


Output :-

enter image description here




To draw an Oval :-

import tkinter as tk
from tkinter import Canvas

app = tk.Tk()
app.title("Canvas")

canvas = Canvas(app)
canvas.pack()

canvas.create_oval(20, 20, 100, 100)

app.mainloop()


Output :-

enter image description here

Please log in to add an answer.