Page 355 -
P. 355

the cost of interactive loveliness





                                                                              You see, GUIs might look
           Frank: What’s up now?
                                                                              nice and easy, but they are
           Joe: Well, it looks like I have to worry about lots of other GUI   actually a pretty complicated
           events, not just my own.                                           beast under the hood. There‛s
                                                                              lots of different events to
           Jim: Yeah. It appears the operating system and this Window
           Manager thing can give the GUI application work to do.             worry about.
           Frank: Yes, that’s right. All that interactive loveliness comes at a
           cost.
           Joe: Cost?!? You mean we have to pay?
           Frank: No, not that sort of cost. You sometimes need to write a little
           extra code to interact with the Window Manager when and where
           necessary... that’s what I mean by “cost.”
           Joe: Phew! So... what’s a Window Manager, anyway?
           Frank: It’s something built into every GUI application that handles
           the management of your application’s windows. Python’s GUI,
           tkinter, has a Window Manager, as do all the other GUI toolkits.
           Joe: So, how do I work with the events generated by the Window
           Manager?
           Frank: You create a function with the code you want to run and
           then connect the function to the event.

           Joe: OK, I get that. But which event do I connect up to? It’s not like
           the Window Manager has a button to click on, is it?
           Jim: That’s a good question... Frank?

           Frank: Well spotted. What happens with the Window Manager is
           that there’s a set of protocol properties that you can interact with as   Joe  Frank
           and when required.
           Joe: Protocol what? Properties?                                                          Jim
           Jim: Yeah, you’ve lost me there, Frank.
           Frank: Yes, protocol properties... they really are not as scary as they
           sound. Remember: with GUIs, it’s all just code.
           Jim & Joe: Where have we heard that before... ?
           Frank: Here, let me show you what I mean...








           320    Chapter 9
   350   351   352   353   354   355   356   357   358   359   360