所以基本上我试图为python应用程序创建基于文本的用户界面。这是我走到这一步:只清除Python中的部分屏幕
#!/usr/bin/env python
# encoding: utf-8
from blessed import Terminal
import sqlite3
import sys
import os
reload(sys)
sys.setdefaultencoding("UTF-8")
db = sqlite3.connect('/Users/JoaoPedro/Desktop/PyTest/Alunos')
c = db.cursor()
term = Terminal()
os.system('clear')
def main (self):
print (term.yellow(" CICS 000009/1 Centro Educacional Charles Darwin z\OS 3.2 "))
print (term.yellow(" TERMINAL: 2297 Sistema de Controle de Notas VITÓRIA/ES "))
print (term.yellow(" ======================================================================================= "))
print (term.move_y(28)) + (term.yellow(" ======================================================================================= "))
matricula = raw_input (term.move(4, 7) + "Matrícula: ")
os.system('clear')
print (term.yellow(" CICS 000009/1 Centro Educacional Charles Darwin z\OS 3.2 "))
print (term.yellow(" TERMINAL: 2297 Sistema de Controle de Notas VITÓRIA/ES "))
print (term.yellow(" ======================================================================================= "))
print
print (term.cyan(" Matrícula Nome Série Turma Nota "))
if matricula in ["/", ""]:
c.execute('select * from A ORDER BY nome')
rows = c.fetchall()
else:
c.execute('select * from A WHERE matricula = ?', (matricula,))
rows = c.fetchall()
for row in rows:
print (term.white((term.move_x(9)) + row[0] + (term.move_x(20)) + row[1] + (term.move_x(56)) + row[2] + (term.move_x(64)) + row[3] + (term.move_x(73)) + row[4]))
print (term.move_y(28)) + (term.yellow(" ======================================================================================= "))
command = raw_input (term.move(27, 2) + "Comando ===> ")
if command == "X":
os.system('clear')
sys.exit()
else:
os.system('clear')
main('self')
main('self')
正如你所看到的,我有打印的顶部,每一个新的查询发生时的底部。现在,这对于像这样的小应用程序来说工作得很好,但是如果我添加更多功能,每次都必须重复同一行代码(顶部和底部)。
我想知道是否有任何方法来保持顶部和底部的静态,只允许程序清除之间的区域......?
哇更换三个打印线的每次出现!这其实很不错,我从来没有想过这个笑话 –