1

I have a program (below) that creates an entry box that shows only '*' when you type in it and it creates a button next to the text box. I want the button to show what has been typed in the entry box while it is being pressed. I have tried to use <Button-1> and <ButtonRelease-1> but to no avail.

import tkinter as tk

def myFunc() :
    #Something#
    pass

root = tk.Tk()
root.title('Password')
password = tk.Entry(root,  show = '*')
password.grid(row = 0, column = 1)
password_label = tk.Label(text = 'Password:')
password_label.grid(row = 0, column = 0)
button = tk.Button(text = '.', command = myFunc)
button.grid(row = 0, column = 2)
JACKDANIELS777
  • 339
  • 1
  • 14
Manav
  • 29
  • 8

2 Answers2

2

Try this:

import tkinter as tk

def show_stars(event):
    password.config(show="*")

def show_chars(event):
    password.config(show="")

root = tk.Tk()
root.title("Password")
password = tk.Entry(root, show="*")
password.grid(row=0, column=1)
password_label = tk.Label(text="Password:")
password_label.grid(row = 0, column=0)
button = tk.Button(text="Show password")
button.grid(row=0, column=2)

button.bind("<ButtonPress-1>", show_chars)
button.bind("<ButtonRelease-1>", show_stars)

Using the bindings that @BryanOakley suggested

TheLizzard
  • 7,248
  • 2
  • 11
  • 31
0

Only if button is pressed it changes the text from * to the text entered.

import tkinter as tk

def myFunc():
    #Something#
    if password.cget("show")=="*":
        password.configure(show="")
    elif password.cget("show") =="":
        password.configure(show="*")

root = tk.Tk()
root.title('Password')
password = tk.Entry(root,  show = '*')
p = password
password.grid(row = 0, column = 1)
password_label = tk.Label(text = 'Password:')
password_label.grid(row = 0, column = 0)
button = tk.Button(text = '.', command = myFunc)
button.grid(row = 0, column = 2)
root.mainloop()
JACKDANIELS777
  • 339
  • 1
  • 14