小编Sak*_*han的帖子

在 Python 中获取单个字符作为输入,无需按 Enter 键(类似于 C++ 中的 getch)

首先,我对Python完全陌生,刚刚开始学习它。我知道很多关于 C++ 的东西,但我只是尝试用 Python 实现其中一些。

我已经对其进行了大量搜索,但找不到任何符合我要求的解决方案。请看下面的代码,

import os

class _Getch:
    """Gets a single character from standard input.  Does not echo to the
screen."""
    def __init__(self):
    try:
        self.impl = _GetchWindows()
    except:
        print("Error!")
    def __call__(self): return self.impl()

class _GetchWindows:
    def __init__(self):
        import msvcrt

    def __call__(self):
        import msvcrt
        return msvcrt.getch()



def mainfun():
    check = fh = True
    while check:
        fh = True
        arr = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
        print ("Welcome to Tic Tac Toe Game!!!\n\n")
        print("Enter 1 to …
Run Code Online (Sandbox Code Playgroud)

python user-input menu getchar python-3.x

5
推荐指数
1
解决办法
3800
查看次数

标签 统计

getchar ×1

menu ×1

python ×1

python-3.x ×1

user-input ×1