Updated 2018-06-14 14:11:45 by bll

Tk differences on Mac OS X  edit

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.

How to determine the appearance color

2018-4-23 (Since the color cannot be retrieved from the system color names)

Use the following applescript:
tell application "System Events"
    tell appearance preferences
        get appearance
    end tell
end tell

Button height

2017-12-12 (Bug)

The height attribute of tk Button for Max OSX does not work. Adjusting height value will not resize the Button height. However, the width attribute works fine.

post by [email protected]

Background color

2017-10-6 (Bug)

(bll 2017-10-6 Forgot to put this one in...)

Aqua theme: The background color of a TFrame is set to 'systemWindowBody'. winfo rgb on this color reports white. but the color is not white.

The background color of . (a normal frame, not a TFrame) is set to white on startup. And . configure -background systemWindowBody sets the color to white.

The Mac OS X background color should not be white, it should be #ececec. Since winfo rgb does not work properly on the mac colors, this makes it difficult to get the proper default color.

I had to hard-code the #ececec color.

Foreground and Background Colors

(Normal Difference)

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.

More label/color issues

(Needs verification. Is systemTransparent a valid background?)

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

(Normal Difference)

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

(Bug)

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

(Normal Difference)

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

(Normal Difference)

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.

However, OSX filesystem does not follow the exact specification. Specifically, the following ranges are not decomposed:

  • U+2000-U+2FFF
  • U+F900-U+FAFF
  • U+2F800-U+2FAFF

To convert with tcllib:
package req unicode
join [split [::unicode::normalizeS C [glob -type d *]] ""] \n 

Using the external iconv program: iconv UTF-8-MAC knows about the ranges that are not decomposed.
# 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

(Non-Issue)

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

(Bug?)

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

(Bug)

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::entry and ttk::spinbox field background

(Bug)

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.

Arabic Language input and displaying in Tk works properly on Mac OS since version 10.9 and Windows Xp and above

On FreeBSD and Linux , Arabic does not work properly. I made this dirty solution : http://wiki.tcl.tk/39542 As long as it's fixed on Mac, I just really need to see it working on Linux and FreeBSD.

A withdrawn window will be deiconified by raise

(Bug)

On Mac OS X, raising a withdrawn window will deiconify the window.
toplevel .t
wm withdraw .t
raise .t

Stippling

OS X doesn't support stippling. The following code produces a solid box instead of a stippled one.
pack [canvas .c] 
.c create rect 100 100 200 200 -fill yellow -stipple gray50