简体   繁体   English

如何在 python 中从右到左输入

[英]How make input from right to left in python

I want change position of my input that I input my value from rigth to left我想改变我输入的 position 我从右向左输入我的值

Python's buit-in input cant't change cursor position Python的内置input不能改变cursor position

在此处输入图像描述

How can I do it in Python我该怎么做 Python

I wrote rinput() function in the input.py我在 input.py 中写了rinput() function

from getch import getch
import os

def rinput():
    weigth = os.get_terminal_size().columns
    value = ""
    start = 0
    print("\033[?25l", end="")
    while True:
        char = getch()
        if char == "\n":
            break
        value += char
        if len(value) % weigth == 0:
            start = len(value) - 1
            print()
        print(value[start:].rjust(weigth), end="\r")
    print("\033[?25h")
    return value

it works very easy它很容易工作

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM