beetlebug

Widgets on Linux

The widgets of Tk and ttk work on Linux with no change to a script. This page shows how they look, how the window scales, and the keys and the text on Linux.

The look

ztk draws each widget with the modern theme: round corners, an accent color, and scrollbars that show while a view scrolls or the pointer is over them. The look is the same on each desktop.

The gallery on Linux with the tab Tree open: a treeview with the folders Documents and Pictures and a selected row
The tab Tree of the gallery: ztk examples/platform-gallery.tcl tab=tree.
The gallery on Linux with the tab Canvas open: a bar chart of five colored bars
The tab Canvas: ztk examples/platform-gallery.tcl tab=canvas.

On Wayland the window follows the dark mode and the accent color of the desktop. ztk reads them from the Settings portal (org.freedesktop.portal.Settings) on the session bus: the keys color-scheme and accent-color of org.freedesktop.appearance. GNOME, KDE Plasma, and the desktops that use the portal of GTK give these keys.

Setting of the desktop What it changes
The dark style, or the dark color scheme The colors of each widget.
The accent color The buttons of the style class primary, the check and radio buttons, the switches, the scales, and the focus ring.
  • ztk::style scheme gives light or dark.
  • . gets <<SchemeChanged>> at a change of the mode, so a script can draw its own colors again (Dark mode).
  • A rule of a style sheet in @media (prefers-color-scheme: dark) has the colors of the dark scheme (Styling).
ttk::label .scheme -text "The scheme is [ztk::style scheme]" -padding 20
pack .scheme
bind . <<SchemeChanged>> {
    .scheme configure -text "The scheme is [ztk::style scheme]"
}

With no portal, and on X11, the window has the light scheme. Start the program with --dark for the dark scheme on each desktop:

ztk --dark app.tcl

The classic theme gives the look of Tk on X11:

ztk::style theme classic

Text and fonts

A font family name in a script selects the installed font of the system with that name. ztk finds the TrueType fonts in ~/.local/share/fonts (or $XDG_DATA_HOME/fonts), ~/.fonts, /usr/local/share/fonts, and /usr/share/fonts. The weight and the slant select the nearest face of the family.

Font On Linux
The default font, TkDefaultFont Inter, the font of ztk.
monospace, TkFixedFont JetBrains Mono, the monospace font of ztk.
Each other family The installed font with that name.
A family that the system does not have JetBrains Mono for a monospace name such as Courier, and Inter for each other name.
ttk::label .a -text "Noto Sans, 14" -font {{Noto Sans} 14}
ttk::label .b -text "Liberation Serif, italic" -font {{Liberation Serif} 14 italic}
ttk::label .c -text "Liberation Mono, bold" -font {{Liberation Mono} 14 bold}
ttk::label .d -text "Inter, the default font"
pack .a .b .c .d -anchor w -padx 16 -pady 4
Four labels on Linux in Noto Sans, Liberation Serif italic, Liberation Mono bold, and Inter
Three installed fonts of Linux and the default font in labels.

font families gives the installed families, and font actual gives the family of the font that ztk draws:

puts [font actual {{noto sans} 12} -family]

ztk reads a font with TrueType outlines and no variations. A font with CFF outlines (as in many .otf files) or a variable font is left out, and its family selects Inter. ztk --headless uses only the fonts of ztk, so a headless run gives the same pictures on each machine.

An emoji shows in color when the system has the font Noto Color Emoji. ZTK_EMOJI_FONT=/path/to/font.ttf names another color emoji font.

The scale

On Wayland each window has the scale of its output, also a fractional scale such as 1.25 or 1.5, and the window draws again when it moves to an output of another scale. Sizes in a script are logical pixels, so a layout keeps its size on each output.

The gallery on Linux at the scale 1
The gallery at the scale 1: ztk --headless --scale 1 --screenshot gallery.png examples/platform-gallery.tcl.

The X11 client draws at the scale 1.

Keys

The keys of Tk work as on X11 Tk: Control, Shift, and Alt in a binding are the keys of those names. The entry and the text widget copy, cut, and paste with Control-C, Control-X, and Control-V, and they undo with Control-Z.

bind . <Control-s> {puts save}
bind . <Control-Shift-s> {puts "save as"}

On Wayland the text of an input method, such as Pinyin or Japanese, goes into an entry or a text widget (text-input-v3). The clipboard is the clipboard of the desktop.

The keyboard focus

Tab and Shift-Tab move the focus between the widgets that take it. The widget with the focus shows a blue focus ring.

The gallery on Linux with the focus ring around the entry
The focus in the entry: ztk examples/platform-gallery.tcl focus=entry.

A narrow window

The widgets keep their logical size in a small window, so a layout that fits a phone also fits a narrow window on the desktop. The gallery puts its two columns in one column under 600 logical pixels:

The gallery on Linux in a narrow window, with its widgets in one column
The gallery at 390 by 844: ztk examples/platform-gallery.tcl size=390x844.

Less motion

When the desktop asks for less motion, ztk::animate shows the end state of each animation at once. ztk reads the setting of GNOME (enable-animations) and of KDE (AnimationDurationFactor) through the portal of the desktop, also when it changes while the app runs. Animation has the details.

The next page, Menus, shows the menus on Linux.