archie/tk3.6/library/demos/dialog
2024-05-27 16:13:40 +02:00

54 lines
2.0 KiB
Tcl

#!/usr/local/bin/wish -f
#
# This script generates a sample dialog box that waits for one of three
# buttons to be pressed, then prints a message and exits.
# Create two frames in the main window. The top frame will hold the
# message and the bottom one will hold the buttons. Arrange them
# on above the other, with any extra vertical space split between
# them.
frame .top -relief raised -border 1
frame .bot -relief raised -border 1
pack .top .bot -side top -fill both -expand yes
# Create the message widget and arrange for it to be centered in the
# top frame.
message .top.msg -text "File main.c hasn't been saved to disk since \
it was last modified. What should I do?" -justify center \
-font -Adobe-helvetica-medium-r-normal--*-240* -aspect 200
pack .top.msg -padx 5 -pady 5 -expand yes
# Create the buttons and arrange them from left to right in the bottom
# frame. Embed the left button in an additional sunken frame to indicate
# that it is the default button.
frame .bot.left -relief sunken -border 1
pack .bot.left -side left -expand yes -padx 10 -pady 10
button .bot.left.button -text "Save File" -command "quit save"
pack .bot.left.button -expand yes -padx 6 -pady 6
button .bot.middle -text "Quit Anyway" -command "quit quit"
button .bot.right -text "Return To Editor" -command "quit return"
pack .bot.middle .bot.right -side left -expand yes -padx 10
# The procedure below is invoked as the action for each of the buttons.
# It prints a message and exits by destroying the application's main
# window.
proc quit button {
puts stdout "You pressed the \"$button\" button; bye-bye!"
destroy .
}
bind .top <Enter> {.bot.left.button activate}
bind .top.msg <Enter> {.bot.left.button activate}
bind .bot <Enter> {.bot.left.button activate}
bind .top <Leave> {.bot.left.button deactivate}
bind .top.msg <Leave> {.bot.left.button deactivate}
bind .bot <Leave> {.bot.left.button deactivate}
bind . <1> {.bot.left.button config -relief sunken}
bind . <ButtonRelease-1> {quit save}
focus .
bind . <Return> {quit save}