Python/Tkinter window events and properties
Question: I've been searching for information on the following Tkinter window features
without success. Platform is Windows, Python 2.7. At the end of this post is
code that can be used to explore Tkinter window events.

  1. How can one detect window minimize/maximize events? The event object returned by binding to a window's event does contain any information about these events. I've searched for protocols (like WM_DELETE_WINDOW) that might expose these events without success.

  2. How can one determine window frame border sizes (not Tkinter frames, the frame the OS places around the container where Tkinter places its widgets)? Is there a non-platform specific way to discover these windows properties or do I need to use platform specific solutions like the win32 api under Windows?

  3. How can one determine a window's visibility, eg. whether a window is invisible or not as set by .withdraw()?

  4. Is it possible to cancel a window event, eg. if one wanted to constrain a window to a certain location on a user's desktop? Returning 'break' from a window's event does not cancel window move or resize events.

Here's sample code for experimenting with Tkinter window events.

    
    
    def onFormEvent( event ):
        for key in dir( event ):
            if not key.startswith( '_' ):
                print '%s=%s' % ( key, getattr( event, key ) )
        print
    
    import Tkinter as tkinter
    root = tkinter.Tk()
    lblText = tkinter.Label( root, text='Form event tester' )
    lblText.pack()
    root.bind( '<Configure>', onFormEvent )
    root.mainloop()
    

Update: Here's what I learned about the following events:

  1. event.type == 22 (one or more of following changed: width, height, x, y)

  2. event.type == 18 (minimized) event.widget.winfo_viewable() = 0 (invisible)

  3. event.type == 19 (restore after minimized)

  4. event.type == 2 (maximize)

  5. event.type == 22 (restore after maximized due to change in width and height)


Answer: Determining window visibility is done with a .winfo_viewable() call. Returns 1
if visible, 0 if not.

If you want to prevent the window from resizing, set up your window the way
you want, then use

    
    
    self.root.minsize(self.root.winfo_reqwidth(), self.root.winfo_reqheight())
    self.root.maxsize(self.root.winfo_reqwidth(), self.root.winfo_reqheight())
    

at the end of your `__init__` call.

To completely disable the window from being moved, then you probably just want
to remove the title bar and frame with `self.root.overrideredirect(True)`.

