This is another possible solution using toplevel:
set message "The quick brown fox jumps over the lazy dog"
if {condition is matched} {
toplevel .new_window
wm title .new_window "Window title"
wm geometry .new_window 320x100
wm minsize .new_window 320 100
wm maxsize .new_window 320 100
wm protocol .new_window WM_DELETE_WINDOW {destroy .new_window}
wm attributes .new_window -topmost yes
set input -1
pack [label .new_window.message -text $message] -fill none -expand 1
pack [frame .new_window.buttons] -fill none -expand 1
pack [ttk::button .new_window.buttons.button1 -text "OK" -command {
set input 1
destroy .new_window
}] -side left -padx 5
pack [ttk::button .new_window.buttons.button2 -text "Cancel" -command {
set input 0
destroy .new_window
}] -side right -padx 5
after 10000 {
if {[winfo exists .new_window]} {
destroy .new_window
if {$input == -1} {
set input 1
}
}
}
}
The variable $input holds the user input value (0 or 1), after a timeout of ten seconds without a click the window will self-close with deafult value of 1 (ok).
Pay attention however, before the click or until the timeout expires the variable $input has the value of -1
EDIT: to avoid the latter uncertain behavior you'll probably want this:
set message "The quick brown fox jumps over the lazy dog"
if {condition is matched} {
toplevel .new_window
wm title .new_window "Window title"
wm geometry .new_window 320x100
wm minsize .new_window 320 100
wm maxsize .new_window 320 100
wm protocol .new_window WM_DELETE_WINDOW {
set input 1
destroy .new_window
}
wm attributes .new_window -topmost yes
if {[info exists input]} {
unset input
}
pack [label .new_window.message -text $message] -fill none -expand 1
pack [frame .new_window.buttons] -fill none -expand 1
pack [ttk::button .new_window.buttons.button1 -text "OK" -command {
set input 1
destroy .new_window
}] -side left -padx 5
pack [ttk::button .new_window.buttons.button2 -text "Cancel" -command {
set input 0
destroy .new_window
}] -side right -padx 5
after 10000 {
if {[winfo exists .new_window]} {
set input 1
destroy .new_window}
}
}
vwait input
}
To pause execution waiting for user input or the dafault answer.
Bye