0

I am trying to make the entry widget show the place holder text like this
But then when you click it it shows nothing in it like it should,
but if you click off of it shows this,
If anyone knows please let me know.
Info on what I'm doing:
This is my first GUI project I'm doing 'on my own' by that i mean no YouTube tutorial. I'm trying to make a password manager
This is my code so far:

from tkinter import *
import os



class PlaceholderEntry(Entry):
    #original code at https://stackoverflow.com/questions/27820178/how-to-add-placeholder-to-an-entry-in-tkinter
    #credit to Nae on stack overflow
    def __init__(self, master=None, placeholder="", placefg='grey', bg='white', fg='black', insertbackground="black", show=None):
        super().__init__(master)

        self.placeholder = placeholder
        self.placefg = placefg
        self.fg = fg
        self.show = show
        self.none = None
        self['bg'] = bg
        self['insertbackground'] = insertbackground
    

        self.bind("<FocusIn>", self.focus_in)
        self.bind("<FocusOut>", self.focus_out)

        self.insert_placeholder()

    def insert_placeholder(self):
        self.delete(0,'end')
        self.insert(0, self.placeholder)
        self['fg'] = self.placefg


    def focus_in(self, *args):
        if self['fg'] == self.placefg:
            self.delete('0', 'end')
            self['fg'] = self.fg
            self['show'] = self.show

    def focus_out(self, *args):
        if not self.get():
            self.insert_placeholder()
        self['show'] = self.none
    

os.system('cls' if os.name == 'nt' else 'clear')#clears terminal

root = Tk() 
root.title("entry")
root.geometry("400x400")#sets window size
root.configure(bg='#222222')#for grey background use #222222

c = ("#ffffff", "#222222", "#111111","#555555","#000000")#colors

username = Entry(root, show="*")

password = PlaceholderEntry(root, show="*", placeholder="password", placefg=c[3], bg=c[2],fg=c[0], insertbackground=c[0])
username.pack()
password.pack()  
root.mainloop()
Delrius Euphoria
  • 14,910
  • 3
  • 15
  • 46

0 Answers0