+ 3
Python show len character in input
my question is simple.but difficult to answer. so i use howw = input("type your word here: ") print(len(list(howw))) it will show how many characters in howw after we hit enter button. how about if i wanted print total characters in howw before we hit enter.i tried using "from threading import Thread".not work yet.any suggestion?
6 odpowiedzi
+ 1
I am sorry I really do not know if a module can do that in the terminal ... But creating your input bar in a window can be done with any graphical library like Tkinter or PyGame.
And as your program begin to be a project (even a small one), it takes some time to do it so I leave it to you ;)
+ 3
x = input("Hello")
print(len(x))
+ 1
For that, you'll need to use events to catch any key event when it is pressed and increment the total for accepted key, and decrement it for delete, keeping the position of the cursor in the string known, to prevent some errors like your program thinking the user reduce the number of character but he is pressing the key supr at the end or delete at the beginning.
But that would also need to know where the user clicked in the string.
For that you should use a graphical library and make an input bar in a window like the JavaScript "prompt". (can be made in the terminal only if the user can't click to change the cursor position)
+ 1
You are welcome :)
0
@Baptiste E. Prunier
im not learn javascript yet
i read something about pyhook module.but i not understand.
or someone can gimme code example to do that?
0
@Baptiste E.Prunier
pygame? nice suggestion.i will learn that today.thnx for the answer ;)