By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,772 Members | 919 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,772 IT Pros & Developers. It's quick & easy.

Capture close window button in Tkinter

P: n/a
I am trying to make a simple data editor in Tkinter where each data
element has a corresponding Entry widget. I have tried to use the
FocusIn/FocusOut events to set a 'hasChanged' flag (if a record has not
changed, the db doesn’t need updating). This seems to work fine except
that when the user finishes and clicks a ‘done’ button or the close
window button (in the root widget) no FocusOut event is triggered. I
can trigger a FocusOut event if the ‘done’ button opens another window
(i.e. a messagebox) that takes focus. Enter and Leave follow the mouse,
but don’t trigger when the user tabs between fields.

Is there a better way to monitor 'hasChanged'? Also, how do I capture
the root window close button?

Thanks,

Bill
Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
William Gill wrote:
I am trying to make a simple data editor in Tkinter where each data
element has a corresponding Entry widget. I have tried to use the
FocusIn/FocusOut events to set a 'hasChanged' flag (if a record has not
changed, the db doesn't need updating). This seems to work fine except
that when the user finishes and clicks a 'done' button or the close
window button (in the root widget) no FocusOut event is triggered. I
can trigger a FocusOut event if the 'done' button opens another window
(i.e. a messagebox) that takes focus. Enter and Leave follow the mouse,
but don't trigger when the user tabs between fields.

Is there a better way to monitor 'hasChanged'?
I'd go with monitoring keypresses in the Entry widget.
Also, how do I capture
the root window close button?


root = Tk()
root.protocol("WM_DELETE_WINDOW", onexit)

Jul 19 '05 #2

P: n/a
Jonathan Ellis wrote:
William Gill wrote:
I am trying to make a simple data editor in Tkinter where each data
element has a corresponding Entry widget. I have tried to use the
FocusIn/FocusOut events to set a 'hasChanged' flag (if a record has not
changed, the db doesn't need updating). This seems to work fine except
that when the user finishes and clicks a 'done' button or the close
window button (in the root widget) no FocusOut event is triggered. I
can trigger a FocusOut event if the 'done' button opens another window
(i.e. a messagebox) that takes focus. Enter and Leave follow the mouse,
but don't trigger when the user tabs between fields.

Is there a better way to monitor 'hasChanged'?

I'd go with monitoring keypresses in the Entry widget.


Well, It doesn't seem logical to do a before and after test of the Entry
values after each keypress, but I suppose I could monitor keypresses,
test event.key for Tab (in case the user tabbed out of the widget w/o
making any changes.

Is that along the lines of what you are suggesting?

Also, how do I capture
the root window close button?

root = Tk()
root.protocol("WM_DELETE_WINDOW", onexit)

I had seen something like this somewhere, but couldn't remember where.
Thanks to your reminder I found an example of "Capturing destroy
events." Since that will allow me to route the exit process through a
tkMessageBox, it may be just as good to continue using FocusIn/FocusOut
events.


Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.