I have an Entry widget inside a Frame. The Frame contains other
widgets as well. I have bound the <Key> event to the Frame, but I
don't want the Frame to receive the event when the Entry widget has
focus.
So, I bound the <Key> event to the Entry widget (bound to method
a_key()). This works, except that both the Entry and Frame widgets get
the event. This also forces me to implement event handlers, which is
fine for the Frame since that's what I want to do. But I want the
Entry to use its default handler, not my own handler. Rather than
duplicate all that functionality, I found I could accomplish this by
temporarily unbinding the events, re-generating the event, and then
re-binding the events, as follows:
def a_key(self, e):
self.top.unbind('<Key>')
self.entry.unbind('<Key>')
self.entry.event_generate('<Key>',
keycode=e.keycode,
keysym=e.keysym,
)
self.entry.bind('<Key>', self.a_key)
self.top.bind('<Key>', self._parent_class__keypress)
return 'break'
This works, but it's kludgy. Is there a better way to do this? I just
want the Entry widget to receive the event when it has focus, behave
in its default manner, and not have the event propagate upward to
containing widgets. 1 2388
Phil Schmidt wrote: I have an Entry widget inside a Frame. The Frame contains other widgets as well. I have bound the <Key> event to the Frame, but I don't want the Frame to receive the event when the Entry widget has focus.
So, I bound the <Key> event to the Entry widget (bound to method a_key()). This works, except that both the Entry and Frame widgets get the event. This also forces me to implement event handlers, which is fine for the Frame since that's what I want to do. But I want the Entry to use its default handler, not my own handler. Rather than duplicate all that functionality, I found I could accomplish this by temporarily unbinding the events, re-generating the event, and then re-binding the events, as follows:
def a_key(self, e): self.top.unbind('<Key>') self.entry.unbind('<Key>') self.entry.event_generate('<Key>', keycode=e.keycode, keysym=e.keysym, ) self.entry.bind('<Key>', self.a_key) self.top.bind('<Key>', self._parent_class__keypress) return 'break'
This works, but it's kludgy. Is there a better way to do this? I just want the Entry widget to receive the event when it has focus, behave in its default manner, and not have the event propagate upward to containing widgets.
You could just find out who has focus (root.focus_get() and compare with
the entry... something like (untested)
def a_key(self, event):
has_focus = root.focus_get()
if theEntry==has_focus:
print "the entry binding"
return "break"
else:
print "the frame binding"
Martin This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Eric Brunel |
last post by:
Hi all,
I was creating a Tkinter widget in the style of the reversed tabs below Excel
worksheets and I stepped in a serious problem: the code I made makes python
crash with a seg fault, bus...
|
by: pavel.kosina |
last post by:
It seems to me that in my "again and again repainting canvas" script the
rendering is slowing down as the time goes.
It is visible even after 10 seconds.
Any idea why?
--
geon
The exception...
|
by: syed_saqib_ali |
last post by:
Please take a look at and run the code snippet shown below.
It creates a canvas with vertical & Horizontal scroll-bars.
If you shrink the window to smaller than the area of the canvas, the...
|
by: William Gill |
last post by:
Is there a simple way to cut and paste from a tkinter text widget to an
entry widget? I know I could create a mouse button event that triggers
a popup (message widget) prompting for cut/paste in...
|
by: syed_saqib_ali |
last post by:
Below is a simple code snippet showing a Tkinter Window bearing a
canvas and 2 connected scrollbars (Vertical & Horizontal). Works fine.
When you shrink/resize the window the scrollbars adjust...
|
by: Avi Kak |
last post by:
Does Tkinter provide a function that returns all the event descriptors
for a given widget class? I am looking for something similar to what
you get in Perl/Tk when you call bind() with a single...
|
by: Kevin Walzer |
last post by:
I'm trying to set the active item in a Tkinter listbox to my
application's currently-defined default font.
Here's how I get the fonts loaded into the listbox:
...
|
by: Stephen M. Gava |
last post by:
Hi all,
I prefer using tkinter to wxpython (so sue me :) and i need to display a
lot of html in a particular app. does anyone know if one of the existing
add on tk html widgets have been wrapped...
|
by: Davy |
last post by:
Hi all,
I have written a simple Tkinter program, that is draw a rectangle in a
canvas, when I press Up key, the rectangle move up. But the program
seems work not properly? My environment is...
|
by: akineko |
last post by:
Hi everyone,
This is a memorandum so that other people can share the info.
The following methods are declared in the Tkinter Button class.
tkButtonDown(), tkButtonEnter(), tkButtonInvoke(),...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |