0

I know it's possible to define a custom "Enter password" dialog, see Implementing a Password Dialog with Tkinter.

But is it possible to re-use tkinter.simpledialog.askstring, as explained in this answer: Python: How to get an entry box within a message box?

and just replace the typed text by **** automatically on each keypress?

Or better, does tkinter.simpledialog already implement a password input dilaog?

Basj
  • 41,386
  • 99
  • 383
  • 673

1 Answers1

3

askstring() function can use the attribute show if you set it to show="*" should do exactly what you need it to do. Example below:

import tkinter as tk
from tkinter.simpledialog import askstring
from tkinter.messagebox import showinfo

root = tk.Tk()
root.withdraw()
password = askstring('Password', 'Enter password:', show="*")
showinfo('Show password', 'password input: {}'.format(password))
Hadi Farah
  • 1,091
  • 2
  • 9
  • 27
  • Thank you very much! and the `withdraw` [was useful as well](https://stackoverflow.com/questions/1406145/how-do-i-get-rid-of-python-tkinter-root-window), thanks for this! – Basj Dec 02 '19 at 12:23