- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to draw an arc on a tkinter canvas?
The Canvas is a rectangular area intended for drawing pictures or other complex layouts. You can place graphics, text, widgets or frames on a Canvas.
To draw an arc on a tkinter Canvas, we will use the create_arc() method of the Canvas and supply it with a set of coordinates to draw the arc. We can use create_arc() to create an arc item, which can be a chord, a pieslice, or a simple arc.
Import the required libraries and create an instance of tkinter frame.
Set the size of the frame using root.geometry method.
Create a Canvas widget and set its height and width. Also, set its background color with bg="blue".
Next, use the create_arc method to draw an arc. Supply the coordinates of the arc and also define the extent of the arc. Here, we have set extent=150.
Finally, run the mainloop of the application window.
# Import the required libraries from tkinter import * # Create an instance of Tkinter Frame root = Tk() # Set the geometry root.geometry("700x350") # Create a Canvas with a background color C = Canvas(root, bg="blue", height=250, width=600) # Coordinates for the arc coord = 100, 50, 500, 300 # Create the arc with extent=150 arc = C.create_arc(coord, start=0, extent=150, fill="red") C.pack(side=TOP, padx=50, pady=50) root.mainloop()
On execution, it will produce the following output −
- How to draw a line on a Tkinter canvas?
- How to draw a dashed line on a Tkinter canvas?
- How to draw a png image on a Python tkinter canvas?
- How to draw a dot on a canvas on a click event in Tkinter Python?
- How to draw an SVG file on an HTML5 canvas?
- How to put an outline on a canvas text on Tkinter?
- How to draw a rectangle on HTML5 Canvas?
- Tkinter - How to put an outline on a canvas text
- How to draw a quadratic curve on HTML5 Canvas?
- How to draw a rounded Rectangle on HTML Canvas?
- How to draw large font on HTML5 Canvas?
- How to create a Button on a Tkinter Canvas?
- How to draw a filled arc in Matplotlib?
- How to draw an oval in HTML5 canvas?