- Trending Categories
- Data Structure
- Operating System
- MS Excel
- 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 colorize the outline of a canvas rectangle in Tkinter?
Let us suppose we have created a rectangle on a Tkinter canvas. The task is to provide the rectangle with an outline that can have a color in it. To provide a border or outline to a rectangle, first define the outline property in the constructor and add a new color value to it.
In this example, we will create a rectangle on a Tkinter canvas and then apply a color to its outline.
#Import the required libraries from tkinter import * #Create an instance of Tkinter Frame win = Tk() #Set the geometry win.geometry("700x350") # Define a Canvas Widget canvas = Canvas(win, width=500, height=350) canvas.pack() # Create a rectangle in Canvas canvas.create_rectangle(100,100,300,300, outline= 'yellow', width=4, fill='green') win.mainloop()
Running the above code will display a window with a rectangle inside the canvas widget.
- Related Articles
- How to colorize the outline of a Tkinter canvas rectangle?
- Tkinter - How to put an outline on a canvas text
- How to make a Tkinter canvas rectangle transparent?
- How to put an outline on a canvas text on Tkinter?
- How to change the thickness of a shape's outline on a Tkinter canvas?
- How to remove the outline of an oval in Tkinter?
- How to clear Tkinter Canvas?
- How to get the coordinates of an object in a Tkinter canvas?
- How to draw a rectangle on HTML5 Canvas?
- How to change the background color of a tkinter Canvas dynamically?
- How to update an image in a Tkinter Canvas?
- How to change the color of a Tkinter rectangle on clicking?
- How to move a Tkinter canvas with Mouse?
- How to add text inside a Tkinter Canvas?
- How to bind a click event to a Canvas in Tkinter?