I have a simple program that makes two password boxes and two buttons that should show and unshow the text in their respective entry boxes. This is my current code:
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="*")
password2 = tk.Entry(root, show="*")
password.grid(row=0, column=1)
password2.grid(row=1, column=1)
password_label = tk.Label(text="Confirm Password:")
password_label.grid(row = 1, column=0)
password_label = tk.Label(text="Password:")
password_label.grid(row = 0, column=0)
button = tk.Button(text = '.')
button.bind("<ButtonPress-1>", show_chars)
button.bind("<ButtonRelease-1>", show_stars)
button.grid(row=0, column=2)
button2 = tk.Button(text = '.')
button2.bind("<ButtonPress-1>", show_chars)
button2.bind("<ButtonRelease-1>", show_stars)
button2.grid(row=1, column=2)
I want to make it so that I can pass an argument to the show_chars
and show_stars
function like this:
def show_stars(entry_box):
entry_box.config(show="*")
def show_chars(entry_box):
entry_box.config(show="")
button.bind("<ButtonPress-1>", show_chars(password))
button.bind("<ButtonRelease-1>", show_stars(password))
button2.bind("<ButtonPress-1>", show_chars(password2))
button2.bind("<ButtonRelease-1>", show_stars(password2))
So that it does not show and unshow the same entry box. Is there any way I can do this?