Python / Tkinter Window Events and Properties

I searched for information on the following functions of the Tkinter window without success. Platform - Windows, Python 2.7. At the end of this message, code is used that can be used to view Tkinter window events.

  • How can I define a window to minimize / maximize events? The event object returned by the window event binding contains information about these events. I was looking for protocols (e.g. WM_DELETE_WINDOW) that could detect these events correctly.

  • How to determine the frame size of the window frame (and not Tkinter frames, the OS frame is placed around the container where Tkinter places its widgets)? Is there a non-platform way to detect these window properties or do I need to use platform solutions like win32 api on Windows?

  • How to determine the visibility of a window, for example. whether the window is invisible or not as set .withdraw ()?

  • Is it possible to cancel a window event, for example. if you want to limit the window to a specific place on the user's desktop? Returning “break” from a window event does not cancel window movement or resizing events.

Here is 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 I learned about the following events:

  • event.type == 22 (one or more of the following changes: width, height, x, y)

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

  • event.type == 19 (recovery after minimization)

  • event.type == 2 (maximize)

  • event.type == 22 (recovery after maximization due to changes in width and height)

+3
1

.winfo_viewable(). 1, , 0, .

, , ,

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

__init__.

, , , self.root.overrideredirect(True).

+2

Source: https://habr.com/ru/post/1771822/


All Articles