Pablo
Pablo

Reputation: 29519

Generate audio bell in terminal using Python

How can I generate audio bell in xterm type terminal?

Upvotes: 8

Views: 6768

Answers (3)

Yuval Adam
Yuval Adam

Reputation: 165282

Simple, print the bell character. In Python:

print('\a')

From bash shell:

echo $'\a'

Note that on some terminals, the bell can be disabled. In others, the bell can be replaced with a visual bell in the shape of a flashing screen background.

Upvotes: 17

Tim Pietzcker
Tim Pietzcker

Reputation: 336308

print("\a") # Python 3

or

print "\a"  # Python 2

See the docs.

Upvotes: 3

Serdalis
Serdalis

Reputation: 10489

For a simple beep, print "\a".

The Control Codes are listed on this page, these are all the characters that should make a terminal perform an action.

Upvotes: 2

Related Questions