Writing text on a canvas
In case we want to write some text on a canvas, we do not need to use an additional widget, such as a Label. The Canvas
class includes the create_text
method to display a string that can be manipulated the same as any other type of canvas item.
It is also possible to use the same formatting options that we can specify to add style to the text of regular Tkinter widgets, such as color, font family, and size.
Getting ready
In this example, we will connect an Entry widget with the contents of a text canvas item. While the input will have the standard appearance, the text on the canvas will have a customized style:

How to do it...
The text item will be initially displayed using the canvas.create_text()
method, with some additional options to use a Consolas font and a blue color.
The dynamic behavior of the text item will be implemented using StringVar
. By tracing this Tkinter variable, we can modify the contents of the item:
import tkinter as tk class App(tk.Tk): def __init__...