Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Python, Lua and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Java, C, C++, Ruby, MySQL and Linux / Tomcat systems

Phone System reconfiguration 11.1.2018 and 12.1.2018 - we are on email but incoming phone not available all the time
Unintelligible behaviour of tk_dialog function

Posted by Dimon (Dimon), 20 February 2007
Being in testing of new script, I saw a strange behavior of standart Tk's dialog showing function - tk_dialog.
The syntax of function call is:
set reply [tk_dialog .some "The Title" "Do you want to say yes?" question 0 Yes No "I'm not sure"]

Zero means the index of the button that is to be the default button of the dialog (0 for the leftmost button, and so on). There are 3 buttons in the sample.

If any button would be pressed by mouse, tk_dialog returns a code: 0 if 1-st button was pressed, 1 if 2-nd and so on.
But when I try to select a buttons with pressing 'tab' key, focus is changing, but I see only one button pressed when Enter key is pressing.  
Can I change buttons focus with keyboard withous mouse?

Posted by admin (Graham Ellis), 21 February 2007
The behaviour is controlled not only by the widgit itself, but also by the window manager.   The windows defaults, etc, get involved too.  So navigation keystrokes may indeed not reach your application.  I think that's what your looking for me to confirm and explain?

Posted by Dimon (Dimon), 21 February 2007
Well Graham, yesterday's evening I have correct that dialog's behavior. I found the next code block in tk_dialog's source code (the 'dialog.tcl' file in tk8.4 library):
# 4. Create a binding for <Return> on the dialog if there is
# a default button.

if {$default >= 0} {
  bind $w <Return> "
     [list $w.button$default] configure -state active -relief sunken
     update idletasks
     after 100
     set ::tk::Priv(button) $default

It means that author has design one common <Return> event for dialog's toplevel form.

Well, I have delete code snippet showed above and have written the next code block to improve tk_dialog's functionality:
# 4. Create a binding for <Return>, <Tab> and <Shift+Tab> on each button of the dialog

# Binding <Tab> event for each button
 set butCount [llength $args]
 for {set i 0} {$i<$butCount} {incr i} {
     bind $w.button$i <Tab> "
     $w.button$i configure -default normal
 if {$i<[expr [llength $args]-1]} { $w.button[expr $i+1] configure -default active } else {$w.button0 configure -default active}

# Binding <Return> event for each button  
 bind $w.button$i <Return> "
     [list $w.button$i] configure -state active -relief sunken
     update idletasks
     after 100
     set ::tk::Priv(button) $i
# Binding <Shift-Key-Tab> event for each button
 for {set i [expr $butCount-1]} {$i>=0} {incr i -1} {
     bind $w.button$i <Shift-Key-Tab> "
     $w.button$i configure -default normal
 if {$i==0} { $w.button[expr [llength $args]-1] configure -default active } else {$w.button[expr $i-1] configure -default active}

It works correctly  

Posted by admin (Graham Ellis), 21 February 2007
Excellent ... I hope you're gooing to submit yor change back to the Tcl team for inclusion in a future release?

This page is a thread posted to the opentalk forum at and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2018: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: • WEB: • SKYPE: wellho