Learning python help

Hi there

I am learning python right now, and am making a simple console game. I just need help with one thing. Is there a way to make python do something when you clck the X or close it in any way? Like store a value in a text file.

Thanks.

if __name__ == "__main__":
	try:
		play_game()
	finally:
		with open("/tmp/exit_message", "w") as f:
			f.write("bye bye!")

:wink:

2 things.

  1. Will that work if someone clicks the X?
    and 2. I’m still learning, so I have no idea how to use that.