python - 画框字符界面的问题
问题描述
我正在开发终端音乐播放器。我几乎制作了画框界面。
如您所见,我打破了右边框 ( "║"
)。我试着做到了。但有些事情是错误的,它不起作用。看看我的代码:
import vlc
import glob
import sys
from termcolor import colored, cprint
def scanfolder(directory, extension):
sfile = glob.glob(f'{directory}*.{extension}')
box1 = colored("║", "yellow", attrs=["bold"])
box2 = colored("╚", "yellow", attrs=["bold"])
box3 = colored("═", "yellow", attrs=["bold"])
box4 = colored("╔", "yellow", attrs=["bold"])
box5 = colored("╗", "yellow", attrs=["bold"])
box6 = colored("╝", "yellow", attrs=["bold"])
x = len(directory)
y = len(extension) + 1
z = len(max(sfile, key=len))
z = z - x - y + 3
box3 = box3 * z
print(box4 + box3 + box5)
for i, track in enumerate(sfile):
trackEn = box1 + str(i + 1) + ". " + str(track[x:-y])
indent = " "
mFactor = z - len(trackEn) #z is the most long track name length, len(trackEn) is any other track's length
indent = indent * mFactor #space * mFactor, used to align box drawing character ║, so they can make one solid wall
print(trackEn + indent + box1) #track name + aligning spaces + ║
print(box2 + box3 + box6)
sext = input("Choose extension: ")
sdir = input("Choose directory: ")
cprint("""
________ ________ ______
___ __ \_____ _____ __ \___ /______ ______ __
__ /_/ /__ / / /__ /_/ /__ / _ __ `/__ / / /
_ ____/ _ /_/ / _ ____/ _ / / /_/ / _ /_/ /
/_/ _\__, / /_/ /_/ \__,_/ _\__, /
/____/ /____/ """, "yellow", "on_blue", attrs=["bold"])
scanfolder(sdir, sext)
chooseTrack = colored("Choose track", "green", attrs=["bold"])
colon = colored(": ", "green", attrs=["bold", "blink"])
trackn = input(chooseTrack + colon)
解决方案
推荐阅读
- android - 如果我在一项活动中更改不同布局的可见性而不是开始新活动怎么办?
- javascript - 选择和取消选择某些单选按钮时切换元素可见性
- html - 在 Elm 中更新 contenteditable div 时光标位置丢失
- npm-install - 在 Windows 10 上设置 NPM
- php - 如何从不相关的表中创建视图
- angular - Angular 6交互式递归对象列表
- c++ - 对结构向量进行两次排序
- java - 将字节数组转换为 OutputStream
- javascript-automation - 使用 JavaScript 与 AppleScript 的 MacOS 联系人详细信息
- node.js - 在不查询文档的情况下更新部分字符串