The show parameter takes a value, not a callback. Tkinter takes your callback object and tries to convert it to a string, and this is what you get when you type in the input field.
Instead, you can reconfigure your entry after input using the binding:
def key(event): entry.configure(show = random_char()) entry = tk.Entry (self) entry.pack() entry.bind("<Key>", key)
EDIT
Brian Oakley is right because it will change all characters to the same random character that you type. Displaying different random characters as you type is not the way you should use the Entry widget. You can try something like:
def key(event): global real_password global garbage current_len = len(v.get()) if event.char and event.char in string.ascii_letters: real_password += event.char garbage += random_char() garbage = garbage[:current_len] v.set(garbage) v = tk.StringVar() real_password = "" garbage = "" entry = tk.Entry (self, textvariable = v) entry.pack() entry.bind("<KeyRelease>", key)
Of course, there are many restrictions, the last character entered changes when the key is not released when it is pressed, so you need to type fast :), there is no control over the cursor keys, etc. But in any case, it was fun.
source share