Simple Example 1 of Canva widget

 from tkinter import Tk, Canvas


# Create the main window

root = Tk()

root.title("Canvas Example")


# Create a Canvas widget

canvas = Canvas(root, width=600, height=500, bg="white")

canvas.pack()


# Draw a line

canvas.create_line(50, 50, 200, 200, fill="blue", width=3)


# Draw a rectangle

canvas.create_rectangle(150, 200, 250, 100, fill="red", outline="black")


# Draw an oval

canvas.create_oval(250, 100, 300, 200, fill="green")


# Draw a polygon

canvas.create_polygon(150, 300, 250, 250, 350, 300, fill="purple", outline="black")


# Draw some text

canvas.create_text(300, 50, text="Welcome in tkinter Blog of Dr.Poonam ", font=("Arial", 20), fill="Green")


# Start the Tkinter event loop

root.mainloop()


output:







Comments