Python Code Screenshots — What the Highlighter Marks

49 keywords · # and triple quotes comments · rendered in the Saffron default palette

Indentation carries the structure in Python, so a screenshot lives or dies on preserving whitespace. Keywords, comments and all three string forms are recognised, and a docstring keeps its internal hash marks unstyled.

A short Python snippet

# group words by length
words = ["fig", "plum", "apple"]
buckets = {}
for w in words:
    buckets.setdefault(len(w), []).append(w)
print(buckets)

What gets coloured

Token classRuleHow it looks
Comments# line, plus triple-quoted stringsMuted, never competing with the code
StringsSingle, double and triple quotedDistinct from identifiers at a glance
Keywords49 reserved wordsAccent colour, the loudest thing on the page
NumbersIntegers and decimalsSame weight as code, no outline box
Function callsIdentifier followed by a parenthesisSlightly heavier than plain identifiers

Rendering it as an image

Paste the snippet into the tool, pick a theme and an export width. The renderer keeps your indentation, wraps long lines only when you ask it to, and can export either a flat PNG or a transparent one for slides. The default window chrome is optional, so a two-line example does not have to look like a browser window.

Other languages

Frequently asked questions

How many keywords does the Python highlighter know?
It ships a fixed list of 49 words for Python. The list is deliberately flat rather than a full grammar: the tool exists to make a snippet legible in a screenshot, not to type-check it, so contextual keywords that need parsing stay in the plain text colour.

What happens to code the highlighter misreads?
Nothing is rewritten. Highlighting only adds colour spans on top of the exact characters you pasted, so the exported PNG always contains your original text. A keyword inside a string stays a string, and a comment marker inside a string is not treated as a comment.

Try it with your own Python: the Code2Image code to image generator is entirely client-side, so the snippet never leaves the browser.