TIP 604: Printing Support for Text and Canvas Widgets

Author:         Kevin Walzer <[email protected]>
State:          Final
Type:           Project
Created:        03-July-2021
Keywords:       Tk, desktop integration
Tcl-Version:    8.7
Vote:			Done
Vote-Summary:   Accepted 9/0/0
Votes-For:      MC, JD, KK, FV, DKF, JN, SL, BG, KW 
Votes-Against:  none
Votes-Present:  none
Keywords:		Tk, desktop integration


Most GUI tookits provide an interface to send graphic and text output to a device such as a laser printer. Various extensions and command-line calls have allowed Tk to have rudimentary printing support, but there has never been a consistent API within Tk to offer printing. This TIP proposes to establish a consistent API in Tk to support printing with platform-native dialogs when possible, and with a Tk dialog to drive command-line configuration on other platforms.


Existing code from the GDI and cocoaprint extension packages has been refactored and ported into Tk's core; the authors have granted permission to incorporate their code under Tk's BSD-style license. The X11 development will be a Tk dialog that will drive the "lpr" or "lp" commands.

The tk print commands will present a script-level public API implementing the proposed interface, outlined below.

tk print window

This command prints the contents of a canvas or text widget.


A full demonstration of these commands in action has been added to the Tk widget demo under the "Common Dialogs" section, "Printing from canvas and text widgets." Since the API is very simple, one can get a better understanding of the functionality by actually testing it in the demo.


A draft implementation is currently under development in the tk_print branch.


This document has been placed in the public domain.