O'Reilly logo

Python 2.6 Graphics Cookbook by Mike Ohlson de Fine

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Simple text

This is how to place text onto your canvas.

How to do it...

  1. In a text editor, type the code given in the following code.
  2. Save this as a file named text_1.py, inside the directory called constr again.
  3. As before, open up an X terminal or DOS window if you are using MS Windows.
  4. Change directory into constr - where text_1.py is located.
  5. Type text_1.py and your program should execute.
    # text_1.py
    #>>>>>>>>>>
    from Tkinter import *
    root = Tk()
    root.title('Basic text')
    cw = 400 # canvas width
    ch = 50 # canvas height
    canvas_1 = Canvas(root, width=cw, height=ch, background="white")
    canvas_1.grid(row=0, column=1)
    xy = 150, 20
    canvas_1.create_text(xy, text=" The default text size looks \ about 10.5 point")
    root.mainloop()
    

How it works...

The results ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required