使用Click的清除功能

问题描述 投票:0回答:1

我正在用Python创建一个项目,该项目要求在特定点清除外壳窗口。我尝试了几种清除外壳的方法,但没有一种对我有用。我问了我的一些编程朋友,他们告诉我使用Click库。

我的清除函数调用此:

click.clear()

但是,当我在外壳中运行此程序时,什么也没有发生。没有错误消息,但也没有任何效果。我正在使用Python 3.5.1。难道我做错了什么?

这里是完整代码:

# Word Game
import random
import time
import click
def clearshell():
  click.clear()
loopy = True
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 
's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
random.shuffle(alphabet)
b = alphabet[0:16]
answers = []
game = True
while game == True:
  print(' Use the letters in the grid to form a word.\n You are allowed to repeat letters (ex. 
  \'letter\')')
  print(' The letters do NOT have to be connected. You may use any letters in the box together.')
  print(' If you repeat a word that another player has entered, you\'ll be eliminated.')
  print('   ')
  print('', b[0], b[1], b[2], b[3], '\n', b[4], b[5], b[6], b[7], '\n', b[8], b[9], b[10], b[11], 
  '\n', b[12], b[13], b[14], b[15])
  print('   ')
  answer = input(' Word? ')
  if answer.lower() in answers:
    time.sleep(0.1)
    game = False
  else:
    answers.append(answer.lower())
  clearshell()
print('You have been eliminated!')
print('List of words:')
for x in range(len(answers)):
  print(answers[x])  
for x in range(3):
  print('   ')
python libraries
1个回答
0
投票

只需替换为此功能。我已经使用了system模块中的os方法:

from os import system
def clearshell():
    system('cls') #for windows
    #system('clear') <-- for linux/macOS
© www.soinside.com 2019 - 2024. All rights reserved.