[Idle-dev] IDLE getpass?

Tal Einat taleinat at gmail.com
Sun Jul 29 23:16:11 CEST 2007


On 7/26/07, Douglas S. Blank <dblank at brynmawr.edu> wrote:
> Tal Einat wrote:
> > On 7/26/07, Douglas S. Blank <dblank at brynmawr.edu> wrote:
> >> Is there an easy way that one can enter a password in IDLE but not have
> >> the characters show (or just show asterisks)? The only way I can think of
> >> is to bind(<KeyPress>) but that seems to be overkill. I'm looking for
> >> something like replacing sys.stdout or some Tkinter function. Any hints
> >> appreciated.
> >
> > A good starting point would be:
> >
> > from tkSimpleDialog import askstring
> > askstring('Enter Password', 'Password: ', show='*')
> >
> > You'd have to work out a few Tk kinks to get it to work smoothly...
> > but it works.
>
> Thanks for the pointer. This brings up some additional questions:
>
> 1) It looks like that the trick here is to set
> entry.configure(show='*'). Can that be done in the Python Shell in IDLE?
> That is, can one temporarily make all characters that you type in the
> Python Shell be *?

Not on the Tk level as you can with Entry widgets. But an IDLE
extension can hook on to the EditorWindow object's 'write' method, and
change it to show an asterisk ('*') instead of any input. You could
write an extension for password entry, which temporarily overrides
this 'write' method, and when the user is done returns the write
method to its original form. You'd have to be a bit careful though,
for instance, make sure the shell is restored if the user hits Ctrl+C.

> 2) How does one get a hold of the PyShell once IDLE has already started?
> (If this is possible, I'd like to know for other reasons besides this one).

Well, that's precisely what extensions get - the EditorWindow object,
which is the PyShell object in the case of the shell window.

> 3) If I have to open a Tk window, how can I get it to appear on top of
> the IDLE window?

IIRC this depends on your window manager. Tk's 'raise' command
('tkraise' in Python's Tkinter, because 'raise' is a Python keyword)
just doesn't work on windows - this is a well known bug. I seem to
recall that the TopLevel widgets' 'wm_deiconify' method has something
to do with it... Try a Google Groups search on this issue + Tk, and
you should find an answer.

> Thanks for any additional hints,
>
> -Doug

Sorry for the unusually delayed reply!
- Tal


More information about the IDLE-dev mailing list