+ 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?

19th Aug 2017, 6:38 AM
Kevin AS
Kevin AS - avatar
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 ;)
19th Aug 2017, 7:07 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 3
x = input("Hello") print(len(x))
19th Aug 2017, 6:48 AM
Iwan
Iwan - avatar
+ 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)
19th Aug 2017, 6:49 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 1
You are welcome :)
19th Aug 2017, 11:53 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
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?
19th Aug 2017, 7:05 AM
Kevin AS
Kevin AS - avatar
0
@Baptiste E.Prunier pygame? nice suggestion.i will learn that today.thnx for the answer ;)
19th Aug 2017, 7:14 AM
Kevin AS
Kevin AS - avatar