diff --git a/src/message_window.py b/src/message_window.py
index f4bf614a23a4fd850647d8e179d55970a0a35d5a..1b4a8ea37928966092fd8bc62560e549189320ef 100644
--- a/src/message_window.py
+++ b/src/message_window.py
@@ -764,6 +764,9 @@ class MessageWindow(object):
 			old_ctrl.set_control_active(False)
 
 		new_ctrl = self._widget_to_control(notebook.get_nth_page(page_num))
+		if not new_ctrl:
+			# This event is sometimes exposed without any reason. see #5366
+			return
 		new_ctrl.set_control_active(True)
 		self.show_title(control = new_ctrl)