TIP 496: Display hints in ::entry ::spinbox ::ttk::entry ::ttk::spinbox and ::ttk::combobox

Login
Bounty program for improvements to Tcl and certain Tcl packages.
Author:         René Zaumseil <rzaumseil@kkg.ch>
State:          Draft
Type:           Project
Vote:           Pending
Created:        17-Jan-2018
Post-History:   
Keywords:       Tk
Tcl-Version:    8.7

Abstract

Entry fields should support the ability to display informational text when no text is given.

Rationale

Entry fields, for instance search boxes in browsers, have the ability to display some help text inside if no real value is given. The text is with a lighter color and is removed if the user enters some real text.

The entry, spinbox, ttk::entry, ttk::spinbox and ttk::combobox commands can easily be enhanced to provide this support, and there is no interference with existing code as this functionality can be done by just introducing new options.

Specification

A help text can be displayed on entry, spinbox, ttk::entry, ttk::spinbox and ttk::combobox widgets if no text is otherwise displayed. To control the text appearance the following new options will be added:

-placeholder: The string to display.

-placeholderforeground: The color of the text. This is a normal option for the Tk widgets and a style option for the Ttk widgets.

If the -placeholder text is empty (the default value) then nothing is displayed.

The -placeholderforeground has a default value of #b3b3b3 (gray70).

The -placeholder text value is always displayed with current font and justification.

Implementation

A patch implementing these changes is available in the fossil repository in the tip-496 branch.

Documentation updates not yet done.

Example of use

    package require Tk
    # tk entry
    grid [::ttk::entry .e];#normal display
    .e configure -placeholder test;#display text is: test
    .e configure -placeholderforeground red;#display text is now red
    .e insert end xxx;#display text is xxx, color is black
    .e configure -textvariable a; set a yyy;##display text is yyy
    set a {};#display text is test, color is red
    # ttk entry
    ttk::entry .e1
    ttk::style configure TEntry -placeholderforeground red
    .e1 configure -placeholder test

Copyright

This document has been placed in the public domain.

History