我想在Python中使用以下ascii characteres创建菜单框:
ASCII码200 =╚(箱形图字符双线左下角)
ASCII码201 =╔(箱形图字符双行左上角)
ASCII代码202 =╩(框图绘制字符双线水平向上)
ASCII码203 =╦(箱形图字符双线水平向下)
ASCII码204 =╠(箱形图字符双向垂直和右侧)
ASCII码205 =═(箱形图字符双横线)
ASCII码206 =╬(箱形图字符双线水平垂直)
然而,似乎不支持这些。当我使用chr()时,系统会打印完全不同的东西。
您对如何使用Python 3打印上述字符有任何建议吗?
谢谢。
答案 0 :(得分:4)
它似乎适用于字符串文字:
>>> symbs = [u'\u255a', u'\u2554', u'\u2569', u'\u2566', u'\u2560', u'\u2550', u'\u256c']
>>> for sym in symbs:
... print(sym)
...
╚
╔
╩
╦
╠
═
╬
这似乎适用于我尝试过的所有平台,Windows 7,Mac OS,Linux等。
代码来自http://svn.python.org/projects/stackless/trunk/Lib/encodings/cp720.py
希望这有帮助。
答案 1 :(得分:1)
感谢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)