Quick Python question - how to change input to *

  • Context: Python 
  • Thread starter Thread starter zeion
  • Start date Start date
  • Tags Tags
    Change Input Python
Click For Summary

Discussion Overview

The discussion revolves around how to modify user input in Python so that it displays as asterisks while typing, similar to password input. Participants explore various methods and modules available in Python, including raw_input, getpass, curses, and Tkinter, to achieve this functionality.

Discussion Character

  • Homework-related
  • Technical explanation
  • Exploratory

Main Points Raised

  • One participant inquires about using raw_input to mask input with asterisks while typing.
  • Another suggests modifying the getpass module to achieve the desired effect, noting it may only work in terminal environments.
  • A participant reports an issue with getpass on a PC, receiving warnings about echo control on the terminal.
  • There is a question about using the curses module for this purpose.
  • Another participant mentions that using cmd might be necessary for certain functionalities and suggests using sys.stdin or msvcrt to print asterisks instead.
  • One participant clarifies their goal is to create a game where input should not be visible to another player and asks about deleting displayed lines.
  • There is a question regarding whether the implementation is in terminal or GUI.
  • A suggestion is made that Tkinter has an option for a text entry box that can mask input with asterisks.
  • Another participant confirms they are using a GUI and seeks clarification on the mentioned modules.
  • It is noted that Tkinter is the default GUI toolkit for Python and that it should have provisions for password entry.

Areas of Agreement / Disagreement

Participants express various methods to achieve the input masking, but there is no consensus on a single solution. Multiple approaches are discussed, and some participants express uncertainty about the effectiveness of certain methods in different environments.

Contextual Notes

Limitations include potential issues with terminal compatibility, the specific environment being used (PC, terminal, or GUI), and the need for further clarification on the capabilities of different Python modules.

zeion
Messages
455
Reaction score
1

Homework Statement



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.

Homework Equations





The Attempt at a Solution

 
Technology news on Phys.org
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.
 
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.
 
Is there a way to do it with the curses module?
 
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.
 
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?
 
Are you doing it in terminal or GUI?
 
Tkinter, IIRC, has an option for a text entry box where you can mask input with asterisks.
 
jhae2.718 said:
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?
 
  • #10
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?
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
Replies
55
Views
7K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 7 ·
Replies
7
Views
4K
Replies
11
Views
4K
  • · Replies 26 ·
Replies
26
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
Replies
17
Views
10K