I am wondering the best way to go about this in python. Basically what I want is to encrypt a password (using something in python or open source) while masking the password in a wxpython text field(i.e. instead of 'password' it will show '********' on the screen). I realize I can create a event in wxpython to output * for each char instead of the regular char but I'm wondering if there's a way to show a variable amount of '*' to hide the actual length of the password as well. Any suggestions?

7 Years
Discussion Span
Last Post by vegaseat

That's going to be awfully confusing to users.

I mean, they type in the 3rd letter say, think they've got it wrong and look at the screen to see 4 stars.

What do they do next, press delete twice I wager and make a bad situation worse.

Votes + Comments
Programmers rarely think about ux.

Well the simplest solution is just to use the style flag wx.TE_PASSWORD when you create the TextCtrl for the password. That automatically makes the output asterisks.


Salem has a very good point, it would be very confusing to the user to show ***** that does not match the password string in length.


One thing you can do, is to make the password dots less visible from a distance and clear after entry ...

# testing wxPython's
# wx.TextCtrl(parent, id, value, pos, size, style)
# for password entry and masking

import wx

class MyFrame(wx.Frame):
    def __init__(self, parent, mytitle, mysize):
        wx.Frame.__init__(self, parent, -1, mytitle, size=mysize)

        self.pw = wx.TextCtrl(self, -1, value="", size=(200, 20), 
        # optional, make the black dots less visible
        # respond to enter key when focus is on edit1
        self.pw.Bind(wx.EVT_TEXT_ENTER, self.onEnter)
        # label for result
        self.result_label = wx.StaticText(self, -1)

        # this is the main sizer
        sizer_v = wx.BoxSizer(wx.VERTICAL)        
        # framed static box
        sbox = wx.StaticBox(self, wx.ID_ANY,
            "Enter your password below:", size=(200, -1))
        # group widgets vertical in the staticbox
        sizer = wx.StaticBoxSizer(sbox, wx.VERTICAL)        
        sizer.Add(self.pw, 0, wx.ALL|wx.EXPAND, border=5)
        sizer.Add(self.result_label, 0, wx.ALL|wx.EXPAND, border=5)
        sizer_v.Add(sizer, 0, wx.ALL|wx.EXPAND, border=10)        
    def onEnter(self, event):
        pw = self.pw.GetValue()
        # optional, clear the password entry
        self.result_label.SetLabel(pw)  # test

app = wx.App(0)
# create a MyFrame instance and show the frame
MyFrame(None, 'password entry', (220, 150)).Show()
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.