Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
###########################
# Create the dialog
###########################
toplevel .dialog
label .dialog.msg ;# Text supplied by Confirm
pack .dialog.msg -side top -padx 4 -pady 4
button .dialog.ok -text "Ok" -command {
# confirmStatus is a global variable that will
# hold the value corresponding to the button
# clicked. It will also serve as our signal
# to our Confirm procedure that the user has
# finished interacting with the dialog
set confirmStatus 1
}
button .dialog.cancel -text "Cancel" -command {
set confirmStatus 0
}
pack .dialog.ok .dialog.cancel -side left -expand yes
# Set the window title, then withdraw the window
# from the screen (hide it)
wm title .dialog "Please confirm"
wm withdraw .dialog
# Install a binding to handle the dialog getting
# lost. If the user tries to click a mouse button
# in our main application, it gets redirected to
# the dialog window. This binding detects a mouse
# click and in response deiconfies the window (in
# case it was iconified) and raises it to the top
# of the window stack.
#
# We use a symbolic binding tag so that we can
# install this binding easily on all modal dialogs
# we want to create.
bind modalDialog <ButtonPress> {
wm deiconify %W
raise %W
}
bindtags .dialog [linsert [bindtags .dialog] 0 modalDialog]
# Handle the "non-standard window termination" by
# invoking the Cancel button when we receives a
# WM_DELETE_WINDOW message from the window manager.
wm protocol .dialog WM_DELETE_WINDOW {
.dialog.cancel invoke
}
###########################
# Display the dialog
###########################
proc Confirm {msg} {
global confirmStatus
# Save old keyboard focus
set oldFocus [focus]
# Set the dialog message and display the dialog
.dialog.msg configure -text $msg
wm deiconify .dialog
# Wait for the window to be displayed
# before grabbing events
catch {tkwait visibility .dialog}
catch {grab set .dialog}
# Now drop into the event loop and wait
# until the confirmStatus variable is
# set. This is our signal that the user
# has clicked on one of the buttons.
tkwait variable confirmStatus
# Release the grab (very important!) and
# return focus to its original widget.
# Then hide the dialog and return the result.
grab release .dialog
focus $oldFocus
wm withdraw .dialog
return $confirmStatus
}
# Example of using the procedure
set result [Confirm "Reformat hard drive?"]