1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Quick Python question - how to change input to *

  1. Mar 19, 2011 #1
    1. The problem statement, all variables and given/known data


    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?


    2. Relevant equations

    3. The attempt at a solution
  2. jcsd
  3. Mar 19, 2011 #2


    User Avatar
    Gold Member

    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.
  4. Mar 19, 2011 #3
    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.
  5. Mar 19, 2011 #4
    Is there a way to do it with the curses module?
  6. Mar 19, 2011 #5


    User Avatar
    Gold Member

    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.
  7. Mar 19, 2011 #6
    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?
  8. Mar 19, 2011 #7


    User Avatar
    Gold Member

    Are you doing it in terminal or GUI?
  9. Mar 19, 2011 #8


    User Avatar
    Gold Member

    Tkinter, IIRC, has an option for a text entry box where you can mask input with asterisks.
  10. Mar 20, 2011 #9
    I'm doing it in GUI..

    Sorry I don't know what those are. Are they Python modules?
  11. Mar 20, 2011 #10


    User Avatar
    Gold Member

    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?
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: Quick Python question - how to change input to *
  1. Python question (Replies: 2)

  2. Python question (Replies: 1)