Version 1 of Tk differences on Mac OS X

Updated 2016-07-05 03:21:39 by bll

Tk differences on Mac OS X

A collection of differences between Tk on Mac OS X as compared to Linux/Windows. Some of these are normal differences, some are non-issues, some are bugs.

Some of these differences are only found in the aqua theme and are (or should be) noted as such.

These are differences that will require an if statement to check if the code is running on the Mac OS X platform or if the aqua theme is in use.

Hopefully this will be helpful to anyone porting their Tk code across platforms.


Foreground and Background Colors

Aqua theme: There is a limited set of colors that can be used. Widgets generally cannot have their foreground and background colors set.

If you need to set foreground or background colors, use the non-ttk widgets or use a non-aqua theme.

See the colors manual page for a list of Mac OS X colors.


label vs ttk::label

label includes a large amount of x padding that cannot be removed.

package require Tk
frame .f -background cyan
pack .f
label .la -text hello
ttk::label .lb -text hello
pack .la -in .f
pack .lb -in .f

More label/color issues

Create a label with a standard Mac OS X background:

label .l -background systemTransparent

Resizing the window and the label loses the background.


Switching a window to fullscreen mode

To switch a window to fullscreen mode, the window must first be withdrawn.

      # For Linux/Mac OS X:

      set cfs [wm attributes $w -fullscreen]
      if { $::tcl_platform(os) eq "Darwin" } {
        if { $cfs == 0 } {
          # optional: save the window geometry
          set savevar [wm geometry $w]
        }
        wm withdraw $w
      }
      wm attributes $w -fullscreen [expr {1-$cfs}]
      if { $::tcl_platform(os) eq "Darwin" } {
        wm deiconify $w
        if { $cfs == 1 } {
          after idle [list wm geometry $w $savevar]
        }
      }

ttk::scrollbar Styling

Aqua theme: Any use of the -style command with ttk::scrollbar will revert the scrollbar to a non-aqua themed scrollbar. This change cannot be undone.


Localization of standard directory names

Mac OS X uses an unusual method to localize the standard directory names (e.g. Music, Downloads), and a standard glob will pick up the non-localized name. The standard Mac OS X file and directory dialogs will localize the names.


Filesystem names and unicode

Mac OS X stores the filenames in the filesystem as decomposed UTF-8 (NFD). If there is a need to display the filename to the user, the filename can be converted using Tcllib utilities or iconv.

# given a file with a list of decomposed filenames in it...
# iconv does not handle really long lines well, so be sure to put some newlines in.
set convertedoutput [exec iconv -c -f UTF-8-MAC -t UTF-8 $fn]

Menus

The Tk menu command is hooked into the Mac OS X global menubar. If you want a menu without using the global menubar, you will have to write your own top level menu.


Font sizing

Point sized fonts on Mac OS X are not sized properly. A 72 point font is usually 1 inch (2.54 cm) from the bottom descender to the top ascender. On Mac OS X, a 72 point font appears to also include the line spacing above the font.


Font scaling

tk scaling may (*) affect the sizing of fonts specified in points and not the fonts specified in pixels. On Mac OS X, this is backwards. In no situation should a font specified in pixels change sizes when there is a change in tk scaling.

(*) If the computer has the actual screen size configured, it may keep a font size in points set to its proper size.


ttk::notebook layout

For non-aqua themes, the ttk::notebook layout does not seem to be modifiable.

# e.g.
    ttk::style element create Notebook.close image \
      [list $vars(img.inactive) \
        {active pressed !disabled} $vars(img.pressed) \
        {active !disabled} $vars(img.active)] \
        -border {0 0 20 0} -sticky {}
    ttk::style layout Close.TNotebook.Tab {
      Notebook.tab -children {
        Notebook.padding -side left -children {
          Notebook.focus -side left -children {
            Notebook.label -side left -sticky {}
          }
          Notebook.close -side left -sticky {}
        }
      }
    }

ttk::entry and ttk::spinbox field background

Specifying -background for a ttk::entry or ttk::spinbox field on Mac OS X will change the field background color, not the background color. As is usual, the background color for the aqua theme is not changeable.