- 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 reconfigure Tkinter canvas items?
Using the Canvas widget, we can create text, images, graphics, and visual content to add to the Canvas widget. If you need to configure the Canvas item dynamically, then tkinter provides itemconfig(**options) method. You can use this method to configure the properties and attributes of the Canvas items. For example, if we create a line inside the Canvas widget, we can configure its color or width using itemconfig() method.
Example
# 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") # Define a function to delete the shape def on_click(): canvas.itemconfig(line, fill="green") # Create a canvas widget canvas = Canvas(win, width=500, height=300) canvas.pack() # Add a line in canvas widget line = canvas.create_line(100, 200, 200, 35, fill="yellow", width=5) # Create a button to delete the button Button(win, text="Update the Color", command=on_click).pack() win.mainloop()
Output
If you run the above code, it will display a window with a button and a line on the canvas.
Now, click the button to change the color of the canvas item.
- Related Articles
- How to bind events to Tkinter Canvas items?
- How to hide and show canvas items on Tkinter?
- How to clear Tkinter Canvas?
- How to make a Tkinter canvas rectangle transparent?
- How to move a Tkinter canvas with Mouse?
- How to add text inside a Tkinter Canvas?
- How to center an image in canvas Python Tkinter
- How to get coordinates on scrollable canvas in Tkinter?
- How to create a Button on a Tkinter Canvas?
- How to open PIL Image in Tkinter on Canvas?
- How to update an image in a Tkinter Canvas?
- How to draw a line on a Tkinter canvas?
- How to delete lines from a Python tkinter canvas?
- How to draw an arc on a tkinter canvas?
- How to colorize the outline of a Tkinter canvas rectangle?

Advertisements