Garry Hurst
Garry Hurst

Reputation: 103

set window icon tkinter macosx

This line works fine for my Windows program.

When i run this same file on the Mac OS X, I get a blank page instead of my icon.

Here is the windows line:

self.iconbitmap("Boss.ico")

I have searched relentlusly for an answer I want this icon to work on both platforms. self is the root Tk window if your wondering if it's root or not.

Note: I have tried using icns, .xbm , .gif by loading a photo image and setting thru window attributes all produce the same blank page on the mac.

Upvotes: 5

Views: 2353

Answers (4)

freercc
freercc

Reputation: 9

I have a coup. Why not change mind, like this. The emoji library is enough to choose a good-looking icon. We can do that.:-D

Code

Effect

Upvotes: 1

Charlie
Charlie

Reputation: 27

It is showing the icon of the file you are putting in the directory so setting the file to be an app will set the window icon to be the icon of that app. for example: root.iconbitmap("/Users/homedir./Desktop/Test apps/Clicker.app") tk window with icon

Upvotes: 1

kakyo
kakyo

Reputation: 11580

@GarryHurst This is not a solution but I sort of get the idea now:

  1. On Mac, TK decided that the icon will never appear on the window title bar.
  2. Instead, it shows up as the app's Dock icon.

It's most probably a by-design or won't fix issue on their side.

Upvotes: 2

Garry Hurst
Garry Hurst

Reputation: 103

After 5 days of searching, and this post having been viewed at least 15 times I went directly to the tk/tcl documentation. If I understand this correctly, apparently there is no way to properly set the icon for mac OS X without using special library or other sort of hacks. It would be nice if there were a mac specific documentation for the tkinter library but alas there isn't that I have found. here is the part of the documentation I found:

wm iconphoto window ?-default? image1 ?image2 ...? Sets the titlebar icon for window based on the named photo images. If -default is specified, this is applied to all future created toplevels as well. The data in the images is taken as a snapshot at the time of invocation. If the images are later changed, this is not reflected to the titlebar icons. Multiple images are accepted to allow different images sizes (e.g., 16x16 and 32x32) to be provided. The window manager may scale provided icons to an appropriate size. On Windows, the images are packed into a Windows icon structure. This will override an ico specified to wm iconbitmap, and vice versa.

On X, the images are arranged into the _NET_WM_ICON X property, which most modern window managers support. A wm iconbitmap may exist simultaneously. It is recommended to use not more than 2 icons, placing the larger icon first.

On Macintosh, this currently does nothing.

if anyone has a working solution please post this. I want to accomplish this so that any system can open a freshly installed python and run my application without installing any additional library.

Upvotes: 4

Related Questions