473,324 Members | 2,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Capture close window button in Tkinter

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
2 4301
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Matthew Wilson | last post by:
Hi - I wrote this program: import Tkinter root = Tkinter.Tk() root.title('tkfun is tktastic!') cc = Tkinter.Canvas(root, width=400, height=400, bg="white")
4
by: Fuzzyman | last post by:
I'm having trouble implementing my GUI using Tkinter...... I've been working through the Tkinter tutorials from 'Programming Python' and am generally happy enough with the functionality and feel...
2
by: Derek | last post by:
Hello: I want to capture the event when a browser is closing, to give to the user the posibility of close or no this browser. When the browser is closing, this show a confirm window with two...
0
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...
1
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...
4
by: feng | last post by:
Hi, In our asp.net app, we need to capture the event when user close the browser window by clicking on the "x" button. But it doesn't seem to be as easy as it sound. Can someone show me how to...
4
by: Bill Manring | last post by:
I need to capture the event when the user closes the browser in my application. I have some code in the session_End event, which works fine when the session times out, but I need to end the...
10
by: iwl | last post by:
Hi, I tryed askstring to input some text in my script, but some ugly empty Window appears with the Input-Window behind and all together behind my Console showing my script. So all have to...
1
by: destiny007 | last post by:
can any one help me to write code to capture selected text from a page but problem is that i am not able to decide where to call the functio.in this case the function is called in all cases of mouse...
1
isladogs
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...
0
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
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)...
1
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
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....
0
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...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.