#2978 erroneous png-image on MAC OSX

obsolete: 8.5.11


if I create a button with an transparent png-File,
the image is displayed erroneous in the button.

MAC OSX (core); tcl/tk 8.5.11; tkimg 1.4

On other platforms (windows/Linux) the image is shown correct.

test_icon.png = the button-Image
screenshot.png = Screenshot of the erroneous image

Here the test-script:

toplevel .a
image create photo bild1 -file test_icon.png
button .a.b -image bild1
grid .a.b

Am i doing something wrong or is there a bug in tkimg on MAC-Platform?

Thanks for any help!


  • Matthias Meier

    Matthias Meier - 2012-06-25

    The Test-Icon to be displyed on a buton

  • Matthias Meier

    Matthias Meier - 2012-06-25

    screenshot of the button

  • Matthias Meier

    Matthias Meier - 2012-06-25

    All tkImg does is decode the image then use Tk's Photo
    API to let Tk do the remaining. The display of the photo
    is not handled by tkImg. So, my advise would be to file
    a Tk bug report about this and assign it to Kevin Walzer.

    Also specify whether you are using the Cocoa or the
    Carbon implementation of MacOSX. Or, in other
    words, are you using a build from the core-8-5-branch
    or from the tk-cocoa-8-5-backport branch?

    Jan Nijtmans

  • Matthias Meier

    Matthias Meier - 2012-06-25
    • labels: --> 41. Photo Images
    • milestone: --> obsolete: 8.5.11
    • priority: 5 --> 7
  • Jan Nijtmans

    Jan Nijtmans - 2012-06-25
    • assigned_to: nobody --> wordtech
  • Jan Nijtmans

    Jan Nijtmans - 2012-06-25

    B.T.W.: Tk8.6 has a PNG decoder built-in, so the
    tkimg 1.4 package is no longer needed.

  • Donal K. Fellows

    I'm guessing that the background is not being cleared before the image is drawn. While it used to be possible to get away without doing it properly (back when photo images were virtually all opaque) it's really impossible now.

    Which would make this a bug in the button drawing code in tkMacOSXButton.c but I don't know the code well enough to say for sure.

  • Kevin Walzer

    Kevin Walzer - 2012-06-25

    Thanks to Donal for the technical diagnosis--this does indeed appear to be a bug (the image is rendered correctly in a ttk button), so I'll dig in and see what I can do.

  • Kevin Walzer

    Kevin Walzer - 2012-06-27
    • status: open --> open-wont-fix
  • Kevin Walzer

    Kevin Walzer - 2012-06-27

    After doing some additional digging into this, it appears to be a side effect of how NSImage and CoreGraphics render alpha channels in PNG files. The drawing context premultiplies the alpha channel and colors, which causes some transparency to be lost. I don't see any way to work around the issue at the C level. The issue seems limited to Tk buttons because NSButton (under Cocoa) uses NSImage to place images on buttons. ttk buttons and other widgets, such as labels, use Tk image drawing API's directly and thus don't display the issue. The easiest workaround is to use ttk buttons instead of traditional Tk buttons, where the issue is not visible.


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks