Tkinter Text

You can add text to a TKinter canvas with the following code

titletext = canvas.create_text(10, 10, anchor="nw", fill="red")

This creates a canvas text object with the name title text in the colour of red.  The text is anchored by its North West corner so the top left corner of the text will be positioned at position x=10 and y=10.  You can read more about the options for this line at EffBot.

canvas.insert(titletext, 14, "This is the Dice game")

Then it is inserted into the canvas.  There is a good explanation of the different text methods at info host. If you wanted to specify the font used then you have to first import tkFont and then create a new font that can be used. You can read more about the font options here.

titleFont = tkFont.Font(family='Helvetica', size=24, weight='bold')

Leave a Reply

Your e-mail address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.