- 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
Tkinter - How to put an outline on a canvas text
The create_text method of Canvas widget in Tkinter doesn't have an attribute like "outline" or "border" to set an outline around a text object. So, to put an outline on a canvas text, you can follow the steps given below −
Import the required libraries and create an instance of tkinter frame.
Set the size of the frame using root.geometry method.
Create a Canvas widget and set its height and width. Also, set its background color with background="white".
Next, create a text object inside the Canvas using create_text() method. Set the font and color of the text as shown in the example.
Get the bounding box (bbox) of the text item.
Use the bbox data to create a rectangle with an outline.
Finally, run the mainloop of the application window.
# Import tkinter library from tkinter import * # Create an instance of tkinter frame or window root = Tk() # Set the geometry of tkinter frame root.geometry("700x350") # Create a Canvas canvas = Canvas(root, background="white") canvas.pack(expand=True) # Create text inside the Canvas text = canvas.create_text(175, 50, text="Text inside the Canvas", font="Calibri, 20", fill="green") # Get the bounding box of text bbox = canvas.bbox(text) # Outline the canvas text canvas.create_rectangle(bbox, outline="blue") root.mainloop()
On execution, it will produce the following output −
- Related Articles
- How to put an outline on a canvas text on Tkinter?
- How to colorize the outline of a Tkinter canvas rectangle?
- How to change the thickness of a shape's outline on a Tkinter canvas?
- How to colorize the outline of a canvas rectangle in Tkinter?
- How to draw an arc on a tkinter canvas?
- How to add text inside a Tkinter Canvas?
- How to create a Button on a Tkinter Canvas?
- How to draw a line on a Tkinter canvas?
- How to draw a dashed line on a Tkinter canvas?
- How to set the font size of a Tkinter Canvas text item?
- How to update an image in a Tkinter Canvas?
- How to remove the outline of an oval in Tkinter?
- How to draw a png image on a Python tkinter canvas?
- How to put a Tkinter window on top of the others?
- How to insert an image in a Tkinter canvas item?