Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


print_tty() doesn't seem to work on non-black backgrounds #4

trhaynes opened this Issue · 7 comments

4 participants


On a white terminal the qr.print_tty() function prints grey on the white background which doesn't seem to scan.


Darn... I wonder if there's an easy fix for that. Any ideas, @koenbollen ?


I think that changing "\x1b[1;47m" to "\x1b[1;7m" should help.
It would be black on white background and white on black background.

"\x1b[0m" to "\x1b[1;40m" - That one should work better.
Just remember to put out.write("\x1b[0m\n") before out.flush()


someone want to test that out on both a white and black background tty?

def print_tty(self, out=None):
        Output the QR Code to a TTY (potentially useful for debugging).

        If the data has not been compiled yet, make it first.
        if out is None:
            import sys
            out = sys.stdout

        if not out.isatty():
            raise OSError("Not a tty")

        if self.data_cache is None:

        modcount = self.modules_count
        out.write("\x1b[1;47m" + (" " * (modcount * 2 + 4)) + "\x1b[40m\n")
        for r in range(modcount):
            out.write("\x1b[1;47m  \x1b[40m")
            for c in range(modcount):
                if self.modules[r][c]:
                    out.write("  ")
                    out.write("\x1b[1;47m  \x1b[40m")
            out.write("\x1b[1;47m  \x1b[40m\n")
        out.write("\x1b[1;47m" + (" " * (modcount * 2 + 4)) + "\x1b[0m\n")

Thanks @utek

In the future, a pull request is the way to go [using a branch]. They're pretty easy and means I can just click one button to merge ;)

1. git remote add -f upstream git:// (-f saves us a git fetch upstream)
2. git checkout upstream/master -b tty-fix
3. Make changes then git commit -am "Make print_tty work on both black and white backgrounds. Fixes #4"
4. git push origin tty-fix
5. Go to github, switch to the tty-fix branch, click the pull request button.


Ok :) Next time I'll use pull requests. Thanks again for git hints :)


Hey guys, when I woke up this morning it was already fixed. Nice.
For the record, I would've come up with the same fix.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.