- 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 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.
# 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()
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.
- How to bind events to Tkinter Canvas items?
- How to hide and show canvas items on Tkinter?
- How to clear Tkinter Canvas?
- How to add text inside a Tkinter Canvas?
- How to make a Tkinter canvas rectangle transparent?
- How to move a Tkinter canvas with Mouse?
- Moving balls in Tkinter Canvas
- How to update an image in a Tkinter Canvas?
- How to center an image in canvas Python Tkinter
- How to create a Button on a Tkinter Canvas?
- How to open PIL Image in Tkinter on Canvas?
- How to get coordinates on scrollable canvas in Tkinter?
- 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?