Python 我的程序找不到终端。我做错了什么?
我正在做一个蛇游戏,不久前我遇到了一个问题。我使用windows操作系统来处理“诅咒”,而不是Linux操作系统。所以我决定使用装有Ubuntu的电脑,但现在出现了一个新的错误: 错误:Python 我的程序找不到终端。我做错了什么?,python,ubuntu,Python,Ubuntu,我正在做一个蛇游戏,不久前我遇到了一个问题。我使用windows操作系统来处理“诅咒”,而不是Linux操作系统。所以我决定使用装有Ubuntu的电脑,但现在出现了一个新的错误: 错误: Traceback (most recent call last): File "/home/KMR/Documents/Snake Game .py", line 8, in <module> curses.initscr() File "/usr/lib/python3.5/cu
Traceback (most recent call last):
File "/home/KMR/Documents/Snake Game .py", line 8, in <module>
curses.initscr()
File "/usr/lib/python3.5/curses/__init__.py", line 30, in initscr
fd=_sys.__stdout__.fileno())
_curses.error: setupterm: could not find terminal
可能是它的复制品。每个人都太关注我的头衔而不是帮助我。所以我提出了一个新问题,这样我就能得到一些实际的帮助@R.M.R试着在这里使用一些答案:@TheWrenchintSystem是我在他的原始问题中建议的dup链接….>>是的。但我想我会把它贴在这里给未来的人看,所以他会看的。这很可能解决OP的问题,但你应该解释一下你在做什么以及为什么。例如,如果您有相同的问题,但没有
lxterminal
,初学者可能不知道如何解决它。
# SNAKES GAME
# Use ARROW KEYS to play, SPACE BAR for pausing/resuming and Esc Key for exiting
import curses
from curses import KEY_RIGHT, KEY_LEFT, KEY_UP, KEY_DOWN
from random import randint
curses.initscr()
win = curses.newwin(20, 60, 0, 0)
win.keypad(1)
curses.noecho()
curses.cur_set(0)
win.border(0)
win.nodelay(1)
key = KEY_RIGHT # Initalizing Values
score = 5
snake = [[4,10], [4,9], [4,8]] # Initial snake co-ordinates
food = [10,20] # First food co-ordinates
win.addc(food[0], food[1], '*') # Prints the food
while key != 27:
win.border(0)
win.addstr(0, 2, 'Score :' + str(score) + ' ') # Printing 'Score' and
win.addstr(0, 27, ' SNAKE ') # 'SNAKE' strings
win.timeout(150 - (len(snake)/5 + len(snake)/10)%120)
prevKey = key # Previous key pressed
event = win.getch
key = key if event == -1 else event
if key == ord(' '): # If SPACE BAR is pressed, wait for another
key = -1 # one (Pause/Resume)
while key != ord(' '):
key = win.getch()
key = prevKey
continue
if key not in [KEY_LEFT, KEY_RIGHT, KEY_UP, KEY_DOWN, 27]: # If an invalid key is pressed
key = prevKey
# Calculates the new coordinates of the head of the snake. NOTE: len(snake) increases.
# This is taken care of later at [1].
snake.insert(0, [snake[0][0] + (key == KEY_DOWN and 1) + (key == KEY_UP and -1), snake[0][1] + (key == KEY_LEFT and -1) + (key == KEY_RIGHT and 1)])
# If snake crosses the boundaries, make it enter from the other side
if snake[0][0] == 0: snake[0][0] = 18
if snake[0][1] == 0: snake[0][1] = 58
if snake[0][0] == 19: snake[0][0] = 1
if snake[0][1] == 59: snake[0][1] = 1
# Exit if snake crosses the boundaries (Uncomment to enable)
# if snake[0][0] == 0 or snake[0][0] == 19 or snake[0][1] == 0 or snake[0][1] == 59: break
# If snake runs over itself
def endgame():
if snake[0]in snake[1:]: endgame()
if snake[0] == food:
food = []
score += 1
import curses
import subprocess
def main():
try:
scr = curses.initscr()
except _curses.error:
subprocess.call(['lxterminal', '--command', 'python', __file__])
else:
run_normal_code(scr) #execute above code in this block