If you're new to Python
and VPython: Introduction

A VPython tutorial

Pictures of 3D objects

What's new in VPython 6

VPython web site
VPython license
Python web site
Math module (sqrt etc.)
Numpy module (arrays)


This is documentation for Classic VPython (VPython 6), which continues to be available but is no longer supported. See vpython.org for information on installing VPython 7 or using GlowScript VPython. Documentation is available at glowscript.org by clicking Help.

With the label object you can display 2D text in a box, and the label always faces forward, even if you rotate the scene (for 3D text, see the text object). Here are simple examples (in the second label statement, note the standard Python scheme for formatting numerical values, where 1.5f means 1 figure before the

box(pos=(0,0,0), color=color.red)
label(pos=(0,0.25,0), text='This is a box')
label(pos=(0,-0.25,0), text='pi = %1.5f' % pi)

label There are many additional label options. In the accompanying diagram, a sphere representing the Earth (whose center is at earth.pos) has an associated label with the text "Earth" in a box, connected to the sphere by a line which stops at the surface of the sphere:

earthlabel = label(pos=earth.pos,
    text='Earth', xoffset=20,
    yoffset=12, space=earth.radius,
    height=10, border=6,

A unique feature of the label object is that several attributes are given in terms of screen pixels instead of the usual "world-space" coordinates. For example, the height of the text is given in pixels, with the result that the text remains readable even when the sphere object is moved far away. Other pixel-oriented attributes include xoffset, yoffset, and border. Here are the label attributes:

pos; x,y,z The point in world space being labeled. If there are no offsets (see diagram), the center of the text is at pos

xoffset, yoffset The x and y components of the line, in pixels (see diagram). You can left justify text by setting xoffset = 1 and line = 0 (so the 1-pixel line doesn't show), or right-justify text by setting xoffset = -1 and line = 0.

text The text to be displayed, such as 'Earth'
(Line breaks can be included as \n, as in label.text = "Three\nlines\nof text")

font Name of the desired font; for example, 'sans', or 'serif', or 'monospace' (fixed-width)
Python Unicode strings are supported.

height Height of the font in pixels; default is 13 pixels

color, red, green, blue Color of the text; default is scene.foreground

background Color of the background of the box; default is scene.background

opacity Opacity of the background of the box, default 0.66
(0 transparent, 1 opaque, for objects behind the box)

border Distance in pixels from the text to the surrounding box; default is 5 pixels

box True if the box should be drawn (default), else False

line True if the line from the box to pos should be drawn (default), else False

linecolor Color of the line and box

space Radius in pixels of a sphere surrounding pos, into which the connecting line does not go

See description of Additional Attributes available for all 3D display objects.