Which Tkinter method. Entry is responsible for setting the value of the textvariable?

Asked

Viewed 6 times

0

I created the following Customentry to implement a placeholder:

class CustomEntry(tk.Entry):
    def __init__(self, master=None, placeholder="", cnf={}, fg="black",
        fg_placeholder="grey50", *args, **kw):
        super().__init__(master=None, cnf={}, bg="white", *args, **kw)
        self.fg = fg
        self.fg_placeholder = fg_placeholder
        self.placeholder = placeholder
        self.bind("<FocusOut>", lambda event: self.fill_placeholder())
        self.bind("<FocusIn>", lambda event: self.clear_box())
        self.fill_placeholder()

    def clear_box(self):
        if not self.get() and super().get():
            self.config(fg=self.fg)
            self.delete(0, tk.END)

    def fill_placeholder(self):
        if not super().get():
            self.config(fg=self.fg_placeholder)
            self.insert(0, self.placeholder)

    def get(self):
        content = super().get()
        if content == self.placeholder:
            return ""
        return content

But when I specify a textvariable and recover its value I receive my placeholder as value, I would like to know which Entry method is associated with the textvariable attribute so that I can override the method and prevent it from happening.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.