OpenLibFetch/buttonfade.py

20 lines
No EOL
708 B
Python

import tkinter as tk
class buttonfade(tk.Entry):
def __init__(self, master=None, placeholder="Search Here", *args, **kwargs):
super().__init__(master, *args, **kwargs)
self.placeholder = placeholder
self.insert(0, self.placeholder)
self.config(fg="gray")
self.bind('<FocusIn>', self.on_focus_in)
self.bind('<FocusOut>', self.on_focus_out)
def on_focus_in(self, event):
if self.get() == self.placeholder:
self.delete(0, tk.END)
self.config(fg="black")
def on_focus_out(self, event):
if self.get() == "":
self.insert(0, self.placeholder)
self.config(fg="gray")