Quick Python question - how to change input to *


by zeion
Tags: input, python
zeion
zeion is offline
#1
Mar19-11, 09:00 PM
P: 467
1. The problem statement, all variables and given/known data

Hello,

Just a quick question here for Python.
I'm using raw_input to get the user to type in a string, but I want the letters to display as * (like when you enter a password) as they type it. (But not actually register as *). Is this doable in Python?

Thanks.

2. Relevant equations



3. The attempt at a solution
Phys.Org News Partner Science news on Phys.org
SensaBubble: It's a bubble, but not as we know it (w/ video)
The hemihelix: Scientists discover a new shape using rubber bands (w/ video)
Microbes provide insights into evolution of human language
jhae2.718
jhae2.718 is offline
#2
Mar19-11, 09:13 PM
PF Gold
jhae2.718's Avatar
P: 1,153
You could probably copy and modify the getpass module, which doesn't echo any input to the screen, to echo asterisks instead.

That might only work for terminals, though.
zeion
zeion is offline
#3
Mar19-11, 09:32 PM
P: 467
Yeah.. can't seen to work on a PC.
Getting this:

Warning (from warnings module):
File "C:\Python27\lib\getpass.py", line 92
return fallback_getpass(prompt, stream)
GetPassWarning: Can not control echo on the terminal.
Warning: Password input may be echoed.

zeion
zeion is offline
#4
Mar19-11, 09:32 PM
P: 467

Quick Python question - how to change input to *


Is there a way to do it with the curses module?
jhae2.718
jhae2.718 is offline
#5
Mar19-11, 09:34 PM
PF Gold
jhae2.718's Avatar
P: 1,153
Are you using IDLE? You might have to use cmd for that to work.

Otherwise, if you are using stdin, you might be able to use sys.stdin or the msvcrt module to print asterisks instead of input.

What are you trying to do?

You could probably work something out using curses.
zeion
zeion is offline
#6
Mar19-11, 09:41 PM
P: 467
Actually I'm just trying to write a game where the other player cannot see what was typed. Is there a way to just delete a line that was displayed?
jhae2.718
jhae2.718 is offline
#7
Mar19-11, 09:52 PM
PF Gold
jhae2.718's Avatar
P: 1,153
Are you doing it in terminal or GUI?
jhae2.718
jhae2.718 is offline
#8
Mar19-11, 09:52 PM
PF Gold
jhae2.718's Avatar
P: 1,153
Tkinter, IIRC, has an option for a text entry box where you can mask input with asterisks.
zeion
zeion is offline
#9
Mar20-11, 09:08 AM
P: 467
Quote Quote by jhae2.718 View Post
Tkinter, IIRC, has an option for a text entry box where you can mask input with asterisks.
I'm doing it in GUI..

Sorry I don't know what those are. Are they Python modules?
jhae2.718
jhae2.718 is offline
#10
Mar20-11, 09:10 AM
PF Gold
jhae2.718's Avatar
P: 1,153
Tkinter is the default GUI toolkit for Python. Sys and msvcrt are Python modules, but if you are doing GUI, the toolkit should have a provision for password entry which should suit your needs.

What toolkit are you using?


Register to reply

Related Discussions
Compile Python, Matlab and Python Programming & Computer Science 3
Quick Question on maximum pressure change in a stationary wave Introductory Physics Homework 3
change battery input with a power adaptor Electrical Engineering 8
Python question Engineering, Comp Sci, & Technology Homework 2
Logic question, 3 input OR to 2 input OR Electrical Engineering 9