Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Terry Reedy Newsgroups: comp.lang.python Subject: Re: Adding Icon To Tkinter Window Date: Sat, 5 Mar 2016 16:38:08 -0500 Lines: 33 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de T9dMahXH+QvGSy5Oj5jatwLjuEgA3tuDf0Qt1kAYN/Hg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'skip:[ 20': 0.03; 'elif': 0.04; 'before.': 0.09; 'icon': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'tcl/tk': 0.09; 'window?': 0.09; 'python': 0.10; 'jan': 0.11; '32,': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'reedy': 0.16; 'subject:Adding': 0.16; 'subject:Tkinter': 0.16; 'subject:Window': 0.16; 'tkversion': 0.16; 'version).': 0.16; 'wrote:': 0.16; 'version.': 0.18; 'thanks.': 0.18; 'windows': 0.20; 'os,': 0.22; 'tkinter': 0.22; 'am,': 0.23; 'specified': 0.23; 'tried': 0.24; 'examples': 0.24; 'written': 0.24; 'header:In-Reply-To:1': 0.24; 'install': 0.25; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'ext': 0.27; 'correct': 0.28; 'code': 0.30; 'version,': 0.30; 'error.': 0.31; 'anybody': 0.32; 'statement': 0.32; 'idle': 0.33; 'changing': 0.34; 'worked': 0.34; 'displays': 0.35; 'but': 0.36; 'should': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'received:org': 0.37; 'several': 0.38; 'skip:o 20': 0.38; 'application': 0.39; 'to:addr:python.org': 0.40; 'received:96': 0.63; 'our': 0.64; 'python-list': 0.66; 'here': 0.66; "'if": 0.84; '3.5.1': 0.84; '8.6': 0.84; 'received:fios.verizon.net': 0.91 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: pool-96-227-207-81.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:104114 On 3/5/2016 11:47 AM, Wildman via Python-list wrote: > Anybody have the correct method of adding an icon to a > window? I have found several code examples on the web > but they all result in an error. Thanks. No single simple statement work for all situations. You should have specified OS, Python version, and tcl/tk version. (IDLE's Help -> About IDLE displays full tk version). Here is the current code from idlelib.PyShell, written by Serhiy Storchaka, our current tkinter maintainer. # set application icon icondir = os.path.join(os.path.dirname(__file__), 'Icons') if system() == 'Windows': iconfile = os.path.join(icondir, 'idle.ico') root.wm_iconbitmap(default=iconfile) elif TkVersion >= 8.5: ext = '.png' if TkVersion >= 8.6 else '.gif' iconfiles = [os.path.join(icondir, 'idle_%d%s' % (size, ext)) for size in (16, 32, 48)] icons = [PhotoImage(file=iconfile) for iconfile in iconfiles] root.wm_iconphoto(True, *icons) Non-windows pre-8.5 systems remain stuck with the tk icon. I just tried changing the 'if' line to 'if False:' on my 3.5.1 (8.6.4) windows install and the 2nd, wm_iconphoto block worked here also. It may be that it did not work on windows with 8.5 and before. -- Terry Jan Reedy