Home

If you're new to Python
and VPython: Introduction

A VPython tutorial

Pictures of 3D objects

Choose a 3D object:

Work with 3D objects:

Windows, Events, & Files:

Vector operations

Graphs

factorial/combin

What's new in Visual 5

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

 
label
label

With the label object you can display text in a box. 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 decimal point and 5 after):

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,
    font='sans')

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

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 1 if the box should be drawn (default), else 0

line 1 if the line from the box to pos should be drawn (default), else 0

linecolor Color of the line and box

space World-space radius of a sphere surrounding pos,
into which the connecting line does not go

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