Wednesday, 27 March 2019

Handle signal in Python when Tkinter messagebox is awaiting user response

I'd like to be able to handle signals whilst a Tkinter messagebox (or similar) is open and awaiting user input.

How can I make it so that the handler is called and the program exits?

Here is what I've tried. The messagebox remains open when the signal is triggered.

import signal
import sys
from tkinter import messagebox

def handler(signum, frame):
    print("STOP!")
    sys.exit(1)

signal.signal(signal.SIGINT, handler)

messagebox.showinfo("This is a message box", "This is a message")



from Handle signal in Python when Tkinter messagebox is awaiting user response

No comments:

Post a Comment