Reputation: 13
Im creating a user management system that allows the admin to create user / employee accounts. When using the default tkinter "Entry" widget it places correctly. correct placement
However when i use my version of the tk entry (LabeledEntry), it places like this
this is the code for my altered entry widget:
class LabeledEntry(tk.Entry): #creates a version of the tkEntry widget that allows for "ghost" text to be within the entry field.
def __init__(self, master=None, label = ""): #which instructs the user on what to enter in the field.
tk.Entry.__init__(self)
self.label = label
self.on_exit()
self.bind('<FocusOut>', self.on_exit)
self.bind('<FocusIn>', self.on_entry)
def on_entry(self, event=None):
if self.get() == self.label: #checks if the given label is present
self.delete(0, tk.END) #If the text field of the entry is the same as the label, it is deleted to allow for user input
self.configure(fg = "black") #sets the text color to black
def on_exit(self, event=None):
if not self.get(): #checks if user entered anything into the entry when clicked into it.
self.insert(0, self.label) #If they did not, sets the text to the original label
self.configure(fg = "grey") #and changes the color of the text to grey.
Is there a way to resolve this issue?
Upvotes: 1
Views: 50
Reputation: 168966
You aren't passing master
to the superclass ctor, which is probably part of the issue:
class LabeledEntry(tk.Entry):
def __init__(self, master=None, label = ""):
super().__init__(master=master)
# ...
Upvotes: 3