- 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 colorize the outline of a Tkinter canvas rectangle?
We can create different shapes such as rectangles, arcs, circles, etc., on a Tkinter canvas. Canvas widget has many inbuilt functions and methods which can be used to configure the property of the shapes.
To colorize the outline of a canvas rectangle, we have to specify the color value in the outline property. It applies to the function create_rectangle(top, left, bottom, right) where the outline should be visible.
Example
#Import the required libraries from tkinter import * #Create an instance of Tkinter Frame win = Tk() #Set the geometry win.geometry("700x350") #Create a canvas object canvas= Canvas(win, width= 300, height= 350) #Create a rectangle in canvas canvas.create_rectangle(300,200,10,10, outline= "red", fill= "white") canvas.pack() win.mainloop()
Output
Running the above code will display a rectangle inside the canvas widget.
Observe that we have set the outline of the rectangle as Red.
- Related Articles
- How to colorize the outline of a canvas rectangle in Tkinter?
- How to make a Tkinter canvas rectangle transparent?
- Tkinter - How to put an outline on a canvas text
- 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 draw a rectangle on HTML5 Canvas?
- How to change the background color of a tkinter Canvas dynamically?
- How to change the color of a Tkinter rectangle on clicking?
- How to draw a rounded Rectangle on HTML Canvas?
- How to create a canvas with Rectangle using FabricJS?
- How to move a Tkinter canvas with Mouse?
- How to add text inside a Tkinter Canvas?
- How to reconfigure Tkinter canvas items?

Advertisements