Page 357 -
P. 357

capture the event



                                                                          SOlUTion


                                You were to study the three tkinter properties presented below and see
                                if you could match up the properties to the correct description:

                      WM_TAKE_FOCUS                         A message sent to your main window
                                                             when the operating system is shutting
                                                             down

                      WM_SAVE_YOURSELF                      A message sent to your main window
                                                             when the close-box has been clicked
                      WM_DELETE_WINDOW                      A message sent to your main window
                                                             when the window has been selected
                                                             after a mouse click


                            You were to identify which of these protocol messages you think you
                            need to capture:
                                             WM_DELETE_WINDOW



                                                                               OK... here comes a click
                                                                               on the close box. What‛s my
                          Click!                                               protocol? Ah, yes... it hasn‛t
                                                                               been captured, so I‛ll just
                                                                               execute the default behavior
                                                        ?                      and close that sucker!










           Controlling the Window Manager

           To capture the event before it gets to tkinter, call your app’s   You'll have to create the
           protocol() method and identify the function that should be     “shutdown” function.
           called instead of executing the default behavior:


             Be sure to call      app.protocol("WM_DELETE_WINDOW", shutdown)                 Associate the event-
            “protocol()" BEFORE                                                              handling function
            “mainloop()".                                                                    with the property.

           322    Chapter 9
   352   353   354   355   356   357   358   359   360   361   362