Skip to main content

How to Remove Text Under Barcode with `python-barcode`

· 2 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

By default, the python-barcode library renders human-readable text (usually the encoded number) under the barcode. If you're building a minimal barcode-only label or want to embed the barcode without additional text, you'll need to disable that feature.

Here's how to do it.

Installation

Install the library if you haven't yet:

pip install python-barcode

To enable image output (PNG), install with pillow:

pip install python-barcode[images]

Default Behavior: Text Included

import barcode
from barcode.writer import ImageWriter

ean = barcode.get('ean13', '5901234123457', writer=ImageWriter())
ean.save('barcode_with_text')

This generates a PNG file that includes the barcode and the number below it.

Remove Text Using writer_options

To remove the human-readable text, set the write_text option to False.

import barcode
from barcode.writer import ImageWriter

options = {
'write_text': False # This disables the text under the barcode
}

ean = barcode.get('ean13', '5901234123457', writer=ImageWriter())
ean.save('barcode_no_text', options)

This will generate a clean barcode image without any label underneath.

Optional: Fine-tune Appearance

You can further customize the barcode using other writer_options, such as:

options = {
'write_text': False,
'module_width': 0.2,
'module_height': 15.0,
'quiet_zone': 2.0,
'font_size': 10,
'text_distance': 1.0,
'background': 'white',
'foreground': 'black'
}

Use Cases for Textless Barcodes

  • Embedding into UI designs or printed labels
  • Small labels where space is limited
  • Machine-only scanning (where humans don't need to read the number)

Conclusion

Disabling the text under a barcode in python-barcode is simple and clean. Just use:

options = {'write_text': False}

Further Reading