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.

How to determine if you are in dark mode

2018-10-26 (prior to Mojave, do not know about Mojave)
└ (chrstphrchvz 2018-11-23: yes, this works in Mojave)

Use the following applescript:

tell application "System Events"
    tell appearance preferences
        get dark mode
    end tell
end tell

culler 2019-04-14: The dark appearance preferences setting was added in OSX 10.12. Selecting that setting would cause the menu bar and dock to be displayed in dark colors, but had no effect on the appearance of windows. That changed with 10.14 where selecting the dark setting would change the appearance of all windows. Starting with 10.14 many of the system UI colors would change value when used in dark mode. Windows could choose to always be displayed in either light or dark mode, or to have the mode be determined by the preferences setting. The current core-8-6-branch supports this in many ways which are described in the README file. The command

tk::unsupported::MacWindowStyle isdark window

returns a Boolean value indicating if the window is in dark mode. (The value is always 0 if the command is used in an OS version earlier than 10.14.) The command tk::unsupported::MacWindowStyle appearance window ?newAppearance? allows a window to be always dark, always light, or respond to the preferences setting. Many of the "semantic" UI colors which change value when used in dark mode have been added to the palette of system colors. And the ttk widgets have all been updated to have both dark and light appearances.

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

chrstphrchvz 2018-11-23: in Mojave, this is controlled by which accent color is set, but this will output blue not just for blue but also for any non-blue color except graphite (it's equivalent to knowing whether the close/minimize/zoom buttons are colored). Currently there does not seem to be a way to get the specific non-blue/non-graphite accent color.

culler 2019-04-14: Prior to OSX 10.14 a user could select from one of two appearance colors, either blue or graphite, in the system preferences. This color would be used by native apps, for example, as the color of a checkbox or radio button. In OSX 10.14 this preferences option was renamed as "accent color" and the number of choices was increased to 8. Also Apple added a new UI color named controlAccentColor. Since the core-8-6-branch now includes that "semantic" color as a system color, one can obtain the RGB components of the currently selected accent color with the command

winfo rgb . systemControlAccentColor

This works in all OSX versions but only Mojave offers more than 2 choices. Note, however, that Tk does not use accent colors other than blue or graphite to draw widgets. Those two colors are the only ones supported by the HITools library which is used for drawing many of the Tk widgets.

How to get the highlight color


Use the following applescript:

tell application "System Events"
  tell appearance preferences
    get highlight color
  end tell
end tell

culler 2019-04-14: In the current core-8-6-branch you can get the currently selected highlight color with the command:

winfo rgb . systemSelectedTextBackgroundColor

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]

culler 2019-04-14: Apple's Human Interface Guidelines specify that all PushButtons have the same height. But the current core-8-6-branch does allow resizing the height of a Button. If the requested height is too large to fit in a PushButton, a rectangular BevelButton is used instead. The HIG does allow a BevelButton to have any height. However, BevelButtons have been deprecated as of 10.14, although they are still supported. Apple recommends using either an ImageButton with a label at the bottom or a PushButton containing a single line of text.

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.

culler 2019-04-14: This is no longer the situation in the current core-8-6-branch. The default window background color used in a TFrame is systemWindowBackgroundColor. That is a "semantic" color which changes from light to dark with the appearance selection (on Mojave or later). The command

winfo rbg . systemWindowBackgroundColor

returns the RGB components of the that color. The RGB components will correspond to either the light or dark version of the color, depending on which mode was in effect when the Tcl program started. If the mode is changed while the program is running the color value reported by winfo rgb . does not change. This appears to be a "feature" of the NSColor class.

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.

culler 2019-04-14: This behavior does not occur in the current core-8-6-branch. Note, however, that all windows are drawn over a black background, so the effect of using systemTransparent is the same as using black.

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]

culler 2019-04-14: This is no longer the case. In the current core-8-6-branch a window can be changed to either fullscreen or zoomed state without being withdrawn first. (A fullscreen window has a hidden menu bar and cannot be resized or lowered. A zoomed window fills the entire visual part of the screen, not including the menu bar and the dock, and it can be resized.) The current core-8-6-branch also supports split windows.

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.

bll 2019-6-6: This is no longer the case starting with 8.6.10. MacOS now has its own ttk::scrollbar.

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]



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::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.

culler 2019-04-14: This is no longer the case in the current core-8-6-branch. Setting the -fieldbackground color now changes the text background color inside the editable rectangle of a ttk::entry or ttk::spinbox widget. For backwards compatibility, if the -background color is set but the -fieldbackground color is not, then the -background color is used as the -fieldbackground color. If both colors are set then the -background color is ignored.

bll 2019-04-17:

# fieldbackground set to colA
ttk::style configure TEntry -background colA
# fieldbackground set to colB (starting with 8.6.10)
ttk::style configure TEntry -background colA -fieldbackground colB
# fieldbackground set to colB (starting with 8.6.10)
ttk::style configure TEntry -fieldbackground colB 

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 : 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


On Mac OS X, raising a withdrawn window will deiconify the window.

toplevel .t
wm withdraw .t
raise .t

culler 2019-04-14: This is no longer the case in the current core-8-6-branch. Raising a withdrawn window does not cause it to be deiconified.


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