Python Learner
Python Learner

Reputation: 487

Protocols in tkinter in Python

I am new in Python and I want to use protocols like WM_DELETE_WINDOW, WM_TAKE_FOCUS and WM_SAVE_YOURSELF. I have found an example of WM_DELETE_WINDOW which is clear enough to understand. But I want to understand the rest two protocols. What do they do?

from Tkinter import *
import tkMessageBox

root = Tk()

def on_closing():
    if tkMessageBox.askokcancel("Quit", "Do you want to quit?"):
        root.destroy()

root.protocol("WM_DELETE_WINDOW", on_closing)

root.mainloop()

Upvotes: 3

Views: 9474

Answers (1)

Dante S.
Dante S.

Reputation: 232

I read in another question that WM_TAKE_FOCUS not working correctly. That same question gives an alternative way to accomplish what WM_TAKE_FOCUS would do. If it worked correctly, WM_TAKE_FOCUS would happen when the window is in focus. If you don't know what focus is, you can ask me.

How to handle, when tkinter window gets focus


WM_SAVE_YOURSELF is deprecated, but here are a couple of useful links that may help.

https://effbot.org/tkinterbook/wm.htm#Tkinter.Wm.protocol-method https://en.wikipedia.org/wiki/Snapshot_(computer_storage)

Upvotes: 0

Related Questions