问题描述
我用Google搜索了,发现的是乌龟和tkinter之类的库,对我想要的东西来说太好了
我想要这样的形状
print(" _______")
print("|1 2|")
print("| |")
print("|3 4|")
print(" ------- ")
或这样
print(" _______")
print("| |")
print("| |")
print("| |")
print(" ------- ")
我们有没有一个库可以制作具有不同形状和大小的形状, 比turtle和matplotlib更简单。
解决方法
看看这个库: https://github.com/nschloe/termtables
此在终端上打印表格。
示例:
import numpy
import termtables as tt
numpy.random.seed(0)
data = numpy.random.rand(5,2)
string = tt.to_string(data)
输出:
┌────────────────────┬────────────────────┐
│ 0.5488135039273248 │ 0.7151893663724195 │
├────────────────────┼────────────────────┤
│ 0.6027633760716439 │ 0.5448831829968969 │
├────────────────────┼────────────────────┤
│ 0.4236547993389047 │ 0.6458941130666561 │
├────────────────────┼────────────────────┤
│ 0.4375872112626925 │ 0.8917730007820798 │
├────────────────────┼────────────────────┤
│ 0.9636627605010293 │ 0.3834415188257777 │
└────────────────────┴────────────────────┘
另一种选择是:
https://github.com/zvibazak/termshape
示例:
打印正方形:
from tremshape import get_square
print(get_square(5))
* * * * *
* *
* *
* *
* * * * *