- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- 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 a line on a Tkinter canvas?
Tkinter Canvas widget can be used for multiple purposes such as drawing shapes, objects, creating graphics and images. To draw a line on a Canvas, we can use create_line(x,y,x1,y1, **options) method.
In Tkinter, we can draw two types of lines: simple and dashed. We can specify the type of line using the dash property.
# Import the required libraries from tkinter import * # Create an instance of tkinter frame or window win=Tk() # Set the size of the tkinter window win.geometry("700x350") # Create a canvas widget canvas=Canvas(win, width=500, height=300) canvas.pack() # Add a line in canvas widget canvas.create_line(100,200,200,35, fill="green", width=5) win.mainloop()
Running the above code will display a line on the Canvas widget.
- How to draw a dashed line on a Tkinter canvas?
- How to draw an arc 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 create a Button on a Tkinter Canvas?
- How to draw a rectangle on HTML5 Canvas?
- How to put an outline on a canvas text on Tkinter?
- How to draw a quadratic curve on HTML5 Canvas?
- How to draw a rounded Rectangle on HTML Canvas?
- How to draw a line following mouse coordinates with tkinter?
- Tkinter - How to put an outline on a canvas text
- How do you create a Button on a Tkinter Canvas?
- How do I update images on a Tkinter Canvas?
- FabricJS – How to center a Line object horizontally on a canvas?
- FabricJS – How to center a Line object vertically on canvas?