- 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 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.
- How to colorize the outline of a Tkinter canvas rectangle?
- How to make a Tkinter canvas rectangle transparent?
- Tkinter - How to put an outline on a canvas text
- How to change the thickness of a shape's outline on a Tkinter canvas?
- How to put an outline on a canvas text on Tkinter?
- How to remove the outline of an oval in Tkinter?
- How to draw a rectangle on HTML5 Canvas?
- How to change the color of a Tkinter rectangle on clicking?
- How to draw a rounded Rectangle on HTML Canvas?
- How to change the background color of a tkinter Canvas dynamically?
- How to clear Tkinter Canvas?
- How to get the coordinates of an object in a Tkinter canvas?
- How to set the font size of a Tkinter Canvas text item?
- How to make a Button using the Tkinter Canvas widget?
- Changing the color a Tkinter rectangle on clicking