How to change the thickness of a shape's outline on a Tkinter canvas?


Let us suppose we have created an oval on a Tkinter canvas. The task is to change the thickness of the oval's outline. To change the thickness of the outline, provide a border or outline to a rectangle, define the width property in the constructor and assign it an integer value. You can also define the outline property to set a color to the outline of the oval.

Example

#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 an oval in Canvas
canvas.create_oval(100,300,500,100, outline='green', width=5)

win.mainloop()

Output

Running the above code will display a window containing an oval with a thick green outline.

Updated on: 26-May-2021

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements