0
543views
Write a python program to create different shapes using Canvas class using Python Tkinter
1 Answer
written 2.4 years ago by |
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 :-
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 :-
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 :-