6

I'd like to create menu boxes in Python with the following ascii characteres:

ASCII code 200 = ╚ ( Box drawing character double line lower left corner )

ASCII code 201 = ╔ ( Box drawing character double line upper left corner )

ASCII code 202 = ╩ ( Box drawing character double line horizontal and up )

ASCII code 203 = ╦ ( Box drawing character double line horizontal down )

ASCII code 204 = ╠ ( Box drawing character double line vertical and right )

ASCII code 205 = ═ ( Box drawing character double horizontal line )

ASCII code 206 = ╬ ( Box drawing character double line horizontal vertical )

However it seems that these are not supported. When I use chr() the system prints something totally different.

Do you have any advise on how to print the mentioned characters using Python 3?

Thank you.

7
  • 1
    None of those are ascii, ascii only goes up to 127, and "extended ascii" doesn't mean anything. Commented Sep 5, 2017 at 22:06
  • This may help with your question: codescracker.com/python/program/… Commented Sep 5, 2017 at 22:07
  • 2
    Have you tried print('╬'), etc.? Commented Sep 5, 2017 at 22:23
  • May depend on which OS and terminal emulator/shell/command prompt you are using (and what character sets you can get), but on Windows 7 print('\xc8') thru print('\xce') display those 7 characters for me ( to ) Commented Sep 5, 2017 at 23:05
  • @downshift In Python 3? Commented Sep 5, 2017 at 23:25

2 Answers 2

8

It seems to work with string literals:

>>> symbs = [u'\u255a', u'\u2554', u'\u2569', u'\u2566', u'\u2560', u'\u2550', u'\u256c']
>>> for sym in symbs:
...     print(sym)
... 
╚
╔
╩
╦
╠
═
╬

This appears to work on all platforms I've tried it on, Windows 7, Mac OS , Linux, etc.

Codes gotten from http://svn.python.org/projects/stackless/trunk/Lib/encodings/cp720.py

Hope this helps.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks a lot. This is what I was looking for.
Actually, in general Codepage 437 is a better choice. The codepage you link to is specific for Arabic systems; 437 is the semi-official "original" extended ASCII set.
It was little troublesome to look for all unicodes in the shared link and pick required ones. So, for quick look up, here are unicodes for single& double lined box: DOUBLE_LEFT_TOP = u'\u2554' ╔ DOUBLE_VERTI_PIPE = u'\u2551' ║ DOUBLE_LEFT_BOTTOM = u'\u255a' ╚ DOUBLE_RIGHT_TOP = u'\u2557' ╗ DOUBLE_RIGHT_BOTTOM = u'\u255d' ╝ DOUBLE_HORIZ_PIPE = u'\u2550' ═ SINGLE_LEFT_TOP = u'\u250c' ┌ SINGLE_VERTI_PIPE = u'\u2502' │ SINGLE_LEFT_BOTTOM = u'\u2514' └ SINGLE_RIGHT_TOP = u'\u2510' ┐ SINGLE_RIGHT_BOTTOM = u'\u2518' ┘ SINGLE_HORIZ_PIPE = u'\u2500' ─
3

Follow-up thanks to Dave Edwards ...

class TableBorder:
    def __init__ (self, top_left, top_split, top_right,
        mid_left, mid_split, mid_right,
        low_left, low_split, low_right,
        horizontal, vertical):
        self.top_left = top_left
        self.top_split = top_split
        self.top_right = top_right
        self.mid_left = mid_left
        self.mid_split = mid_split
        self.mid_right = mid_right
        self.low_left = low_left
        self.low_split = low_split
        self.low_right = low_right
        self.horizontal = horizontal
        self.vertical = vertical

Borders0 = TableBorder ('+', '+', '+', '+', '+', '+', '+', '+', '+', '-', '|')
Borders1 = TableBorder (u'\u250c',u'\u252C',u'\u2510',u'\u251C',u'\u253C',u'\u2524',u'\u2514',u'\u2534',u'\u2518',u'\u2500',u'\u2502')
Borders2 = TableBorder (u'\u2554',u'\u2566',u'\u2557',u'\u2560',u'\u256C',u'\u2563',u'\u255a',u'\u2569',u'\u255d',u'\u2550',u'\u2551')

def draw_box (width, height, box):
    span = width-2
    line = box.horizontal * (span)
    print (box.top_left + line + box.top_right)
    body = box.vertical + (' '*span) + box.vertical
    for _ in range (height-1):
        print (body)
    print (box.low_left + line + box.low_right)

draw_box (20, 10, Borders1)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.