0

I have an entry that's within a frame. I want to pass an event from that entry.

Here is code that works, but does not include an entry in a frame:

import tkinter as tk
myUi= tk.Tk()
myFrame = tk.Frame(myUi)
myFrame.pack()
def printMe(event):
    value = event.widget.get()
    print(value)
myEntry = tk.Entry(myUi,name='entry')
myEntry.bindtags(('.entry','Entry'))
myEntry.bind("<KeyRelease>", printMe)
myEntry.pack()
myUi.mainloop()

Here is code that doesn't work:

import tkinter as tk
myUi= tk.Tk()
myFrame = tk.Frame(myUi)
myFrame.pack()
def printMe(event):
    value = event.widget.get()
    print(value)
myEntry = tk.Entry(myFrame,name='entry')
myEntry.bindtags(('.entry','Entry'))
myEntry.bind("<KeyRelease>", printMe)
myEntry.pack()
myUi.mainloop()

1 Answer 1

1

When you put the entry in a frame, it's binding tag contains it's own name plus the name of its ancestors separated by periods. In this specific case, the binding tag for the entry is .!frame.myentry. You can see this by printing out the default bindtags before you change them (eg: print(str(myEntry)))

Since you are changing the binding tags for the entry to be ('.entry', 'Entry'), any bindings on the widget itself (ie: on the binding tag .!frame.entry) will not be associated with the widget.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.