- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
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 change the TKinter canvas line from dash to solid?
Canvas widget is one of the most widely used widgets for graphical representation in a Tkinter application. To display a line in the Canvas widget, we can use the built-in library method create_line(x1,y1,x2,y2, **options).
We can also specify the type of line using the dash property. To change the line type from solid to dash dynamically, we can use configure() method. By passing an empty value to the dash property, we can change the line from solid to dash.
Example
Let us take an example to see how it works.
# Import the required libraries from tkinter import * from tkinter import ttk # Create an instance of tkinter frame or window win=Tk() # Set the size of the tkinter window win.geometry("700x350") def update_line(): canvas.itemconfig(line, dash=()) # Create a canvas widget canvas=Canvas(win, width=400, height=300) canvas.pack() # Create a line canvas.create_line(300, 30, 300, 150, dash=(4, 2), width=5) # create a button to change the dash property of the line ttk.Button(win, text="Change", command=update_line) win.mainloop()
Output
If we run the above code, it will display a dashed line inside the Canvas widget.
- Related Articles
- How to draw a line on a Tkinter canvas?
- How to change the background color of a tkinter Canvas dynamically?
- How to draw a dashed line on a Tkinter canvas?
- How to delete lines from a Python tkinter canvas?
- How to clear Tkinter Canvas?
- How to reconfigure Tkinter canvas items?
- How to change the thickness of a shape's outline on a Tkinter canvas?
- How to change Tkinter Button state from disabled to normal?
- How to remove the dashed line from the Tkinter menu UI?
- How to bind events to Tkinter Canvas items?
- How to remove dashed line from my tkinter menu UI?
- How to change the size of a Dash Graph in Python Plotly?
- How to move a Tkinter canvas with Mouse?
- How to make a Tkinter canvas rectangle transparent?
- How to add text inside a Tkinter Canvas?

Advertisements