Keyboard input/Obtain a Y or N response: Difference between revisions

Tcl version without a console
(Tcl version without a console)
Line 244:
 
=={{header|Tcl}}==
 
Using the console (expects U*Xish <tt>stty</tt>)
 
<lang tcl>proc yesno {{message "Press Y or N to continue"}} {
fconfigure stdin -blocking 0
Line 261 ⟶ 264:
 
set yn [yesno "Do you like programming (Y/N)"]</lang>
 
Without a console (answer in the global variable yn; this should work in any GUI for which there is a TCL):
 
<lang tcl>
proc yesno {message} {
toplevel .msg
pack [label .msg.l -text "$message\n (type Y/N)?"]
set ::yn ""
bind .msg <Key-y> {set ::yn "Y"}
bind .msg <Key-n> {set ::yn "N"}
vwait ::yn
destroy .msg
}
 
yesno "Do you like programming?"
 
</lang>
 
 
{{omit from|PARI/GP}}
Anonymous user