Welcome folks today in this blog post we will be looking at canvas class to draw cricle,rectangles,arcs,ovals and lines shapes
in tkinter
gui desktop app in python. All the full source code of the application is given below.
Get Started
In order to get started you need to install the below library using the pip
command as shown below
pip install tkinter
After installing this library you need to make an app.py
file and copy paste the following code
app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
import tkinter as tk window = tk.Tk() canvas = tk.Canvas(window, bg="white", width=300, height=300) canvas.pack() canvas.create_oval((0, 0, 300, 300), fill="yellow") canvas.create_arc((50, 100, 100, 150), extent=180, fill="black") canvas.create_arc((200, 100, 250, 150), extent=180, fill="black") canvas.create_line((50, 200, 110, 240), fill="red", width=5) canvas.create_line((110, 240, 190, 240), fill="red", width=5) canvas.create_line((190, 240, 250, 200), fill="red", width=5) window.mainloop() |
If you execute the above python script
by typing the below command
python app.py