感谢 stackoverflow 上的另一位成员,今天晚上早些时候我看到了这种很酷的技术。我是 python 的初学者,所以我的大部分学习都是通过阅读我拥有的这本书并编辑代码来了解它是如何工作的。
我正在尝试为菜单底部设计这个:
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X TASK1 X TASK2 X TASK3 X TASK4 X TASK5 X
X [ ] X [ ] X [ ] X [ ] X [ ] X
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
所以你基本上看到了这个:
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X X
X TASK MANAGER - TASK SELECTION X
X X
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X X
X READY TO START? X
X --------------------- X
X PRESS THE 'ENTER' X
X KEY TO BEGIN! X
X --------------------- X
X X
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X TASK1 X TASK2 X TASK3 X TASK4 X TASK5 X
X [ ] X [ ] X [ ] X [ ] X [ ] X
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
底部的目的是,如果您选择说任务 2,那么它只会为选择的任何一个打印一个函数......所以它会是(如果选择了任务 2):
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X X
X TASK MANAGER - TASK SELECTION X
X X
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X X
X READY TO START? X
X --------------------- X
X PRESS THE 'ENTER' X
X KEY TO BEGIN! X
X --------------------- X
X X
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X TASK1 X TASK2 X TASK3 X TASK4 X TASK5 X
X [ ] X [X] X [ ] X [ ] X [ ] X
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
这是当前代码:
def printLine (text = ''):
print('X {: ^47} X'.format(text))
def printSelTitle (text = '', title = None):
print('X{: ^9}'.format(text)),
def printSelCheck (text = '', title = None):
print('X [ ] X'.format(text)),
def printBorder (title = None):
print('X' * 51)
def printBox (*lines, title = None, showBottomBorder = False):
printBorder(title)
printLine()
for line in lines:
printLine(line)
printLine()
if showBottomBorder:
printBorder()
printBox('TASK MANAGER - TASK SELECTION')
printBox('READY TO START?', '-' * 21, "PRESS THE 'ENTER'",\
'KEY TO BEGIN!', '-' * 21, showBottomBorder = True)
printSelTitle('TASK1') and printSelTitle('TASK2')
printSelCheck()
printBorder()
printSelTitle('TASK3')
printSelTitle('TASK4')
printSelTitle('TASK5')
这是当前代码的样子:
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X X
X TASK MANAGER - TASK SELECTION X
X X
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X X
X READY TO START? X
X --------------------- X
X PRESS THE 'ENTER' X
X KEY TO BEGIN! X
X --------------------- X
X X
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X TASK1
X [ ] X
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X TASK3
X TASK4
X TASK5
有什么想法吗?提前感谢您的帮助。
最好的,
史蒂文