qcloseevent - catch close events

Name

qcloseevent — catch close events

Syntax

qcloseevent [widget] cmds

Description

The qcloseevent command allows one to catch the closing of windows (qwidgets and qmainwindows). The programmer can assign Tcl commands to be executed during the closing of the window, useful for cleanup actions or for cancelling the close event.

Arguments

widget

The window for which we want to catch the close event. This has to be qwidget or qmainwindow.

cmds

Tcl statements to be executed when the window closes. This will often be the name of a Tcl procedure. If the procedure returns the string 'ignore' the event is cancelled, and the window will remain visible.

Examples

Ex.1: Catching a close event

# Callback procedure for closeevent
proc ce {} {
	puts "Closing"
	
	set button [qinformation "Closing Window" "Really close window?" OK Cancel]
	if { $button == 1 } {  ; # cancel
		return ignore
	}
}

set w [qwidget ]

# Call 'ce' when closing
qcloseevent $w ce

qshow $w

Example Catching a close event shows the procedure 'ce' assigned as a callback function to be called when the window 'w' is closed. The user is then asked whether he wants the window closed or not. Note that not providing a return value in the proc will accept the event.