TIP 742: Add Mouse Wheel Zoom Support to Tk Console

Login
Bounty program for improvements to Tcl and certain Tcl packages.
    Author:         Eric Taylor et99@rocketship1.me
    State:          Draft
    Type:           Project
    Vote:           Pending
    Created:        04-Dec-2025
    Post-History:   
    Tcl-Version:    9.1
    Keywords:       Tk, console, zoom, mousewheel, accessibility

Abstract

This TIP proposes adding Control+MouseWheel bindings to the Tk console to allow users to increase and decrease font size using the mouse wheel in combination with the Control key, consistent with modern application conventions.

Rationale

Most modern applications (web browsers, text editors, IDEs) support Control+MouseWheel for zooming in and out of content. The Tk console already supports font size adjustment via keyboard shortcuts (Ctrl++ and Ctrl+-) and menu items, but lacks the widely-expected mouse wheel zoom functionality.

Adding this feature would:

  • Improve user experience by matching common UI conventions
  • Enhance accessibility for users who prefer mouse-based interactions
  • Provide a more intuitive way to adjust font size during interactive sessions

Specification

The implementation adds a binding to the console window that:

  • Captures Control+MouseWheel events
  • Generates <<Console_FontSizeIncr>> virtual events when scrolling up (positive delta)
  • Generates <<Console_FontSizeDecr>> virtual events when scrolling down (negative delta)
  • Reuses existing font size adjustment infrastructure

The binding is added in the ::tk::ConsoleInit procedure of tk/library/console.tcl, within the BuildMenus section, ensuring it's available whenever the console is initialized.

Reference Implementation

The implementation modifies tk/library/console.tcl in the ::tk::ConsoleInit procedure:

--- tk/library/console.tcl
+++ tk/library/console.tcl
@@ -104,12 +104,20 @@
 	} else {
 	    AmpMenuArgs .menubar.edit add command -label [mc "&Font..."] \
 		-command [list ::tk::console::FontchooserToggle]
 	}
 	bind Console <FocusIn>  [list ::tk::console::FontchooserFocus %W 1]
 	bind Console <FocusOut> [list ::tk::console::FontchooserFocus %W 0]
+        bind . <Control-MouseWheel> {
+            if {%D > 0} {
+                event generate .console <<Console_FontSizeIncr>>
+            } else {
+                event generate .console <<Console_FontSizeDecr>>
+            }
+        }
+
     }
     AmpMenuArgs .menubar.edit add command -label [mc "&Increase Font Size"] \
 	-accel "$mod++" -command {event generate .console <<Console_FontSizeIncr>>}
     AmpMenuArgs .menubar.edit add command -label [mc "&Decrease Font Size"] \
 	-accel "$mod+-" -command {event generate .console <<Console_FontSizeDecr>>}
     AmpMenuArgs .menubar.edit add command -label [mc "Fit To Screen Width"] \

Platform Considerations

The Tk console is currently available on Windows and macOS. TIP #561 proposes adding console support for Unix/Linux systems. This TIP's implementation would apply to all platforms where the console is available.

The MouseWheel event is supported on Windows, macOS, and X11 (as of Tk 9.0). The %D substitution is expected to provide consistent delta values across platforms, with positive values for scrolling up (away from user) and negative values for scrolling down (toward user).

IMPORTANT: This implementation assumes %D behaves consistently on Linux/X11 with the Tk 9.0 mousewheel implementation. This should be verified through testing on all platforms where the console is available, including Unix/Linux if TIP #561 is accepted.

Alternative platform-specific implementation if %D behavior differs:

if {[tk windowingsystem] eq "x11"} {
    bind . <Control-Button-4> {event generate .console <<Console_FontSizeIncr>>}
    bind . <Control-Button-5> {event generate .console <<Console_FontSizeDecr>>}
} else {
    bind . <Control-MouseWheel> {
        if {%D > 0} {
            event generate .console <<Console_FontSizeIncr>>
        } else {
            event generate .console <<Console_FontSizeDecr>>
        }
    }
}

Backwards Compatibility

This change is fully backward compatible. It adds new functionality without modifying existing behavior or APIs.

Copyright

This document has been placed in the public domain.

History