Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #104104 > unrolled thread
| Started by | Wildman <best_lay@yahoo.com> |
|---|---|
| First post | 2016-03-05 10:47 -0600 |
| Last post | 2016-03-06 00:09 -0600 |
| Articles | 19 — 8 participants |
Back to article view | Back to comp.lang.python
Adding Icon To Tkinter Window Wildman <best_lay@yahoo.com> - 2016-03-05 10:47 -0600
Re: Adding Icon To Tkinter Window Grant Edwards <invalid@invalid.invalid> - 2016-03-05 18:08 +0000
Re: Adding Icon To Tkinter Window Wildman <best_lay@yahoo.com> - 2016-03-05 12:47 -0600
Re: Adding Icon To Tkinter Window Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-09 08:39 -0800
Re: Adding Icon To Tkinter Window - Followup Wildman <best_lay@yahoo.com> - 2016-03-05 12:10 -0600
Re: Adding Icon To Tkinter Window - Followup Christian Gollwitzer <auriocus@gmx.de> - 2016-03-05 19:36 +0100
Re: Adding Icon To Tkinter Window - Followup Wildman <best_lay@yahoo.com> - 2016-03-05 23:53 -0600
Re: Adding Icon To Tkinter Window - Followup Christian Gollwitzer <auriocus@gmx.de> - 2016-03-06 10:16 +0100
Re: Adding Icon To Tkinter Window - Followup Wildman <best_lay@yahoo.com> - 2016-03-06 10:30 -0600
Re: Adding Icon To Tkinter Window - Followup Serhiy Storchaka <storchaka@gmail.com> - 2016-03-09 19:09 +0200
RE: Adding Icon To Tkinter Window - Followup Joaquin Alzola <Joaquin.Alzola@lebara.com> - 2016-03-09 17:14 +0000
Re: Adding Icon To Tkinter Window Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-05 18:38 +0000
Re: Adding Icon To Tkinter Window Wildman <best_lay@yahoo.com> - 2016-03-05 12:50 -0600
Re: Adding Icon To Tkinter Window Serhiy Storchaka <storchaka@gmail.com> - 2016-03-05 21:55 +0200
Re: Adding Icon To Tkinter Window Wildman <best_lay@yahoo.com> - 2016-03-05 23:56 -0600
Re: Adding Icon To Tkinter Window Terry Reedy <tjreedy@udel.edu> - 2016-03-05 16:38 -0500
Re: Adding Icon To Tkinter Window Wildman <best_lay@yahoo.com> - 2016-03-06 00:04 -0600
Re: Adding Icon To Tkinter Window Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-09 08:41 -0800
Re: Adding Icon To Tkinter Window Wildman <best_lay@yahoo.com> - 2016-03-06 00:09 -0600
| From | Wildman <best_lay@yahoo.com> |
|---|---|
| Date | 2016-03-05 10:47 -0600 |
| Subject | Adding Icon To Tkinter Window |
| Message-ID | <tIadnY8e89YQkEbLnZ2dnUU7-LHNnZ2d@giganews.com> |
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. -- <Wildman> GNU/Linux user #557453 The cow died so I don't need your bull!
[toc] | [next] | [standalone]
| From | Grant Edwards <invalid@invalid.invalid> |
|---|---|
| Date | 2016-03-05 18:08 +0000 |
| Message-ID | <nbf7af$lbp$1@reader1.panix.com> |
| In reply to | #104104 |
On 2016-03-05, Wildman <best_lay@yahoo.com> 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. You'll have to be a lot more specific about what you mean by "add an icon to a window". Do you just want to display an .ico file within a window? -- Grant
[toc] | [prev] | [next] | [standalone]
| From | Wildman <best_lay@yahoo.com> |
|---|---|
| Date | 2016-03-05 12:47 -0600 |
| Message-ID | <HLidnWDnssMmtEbLnZ2dnUU7-bWdnZ2d@giganews.com> |
| In reply to | #104106 |
On Sat, 05 Mar 2016 18:08:15 +0000, Grant Edwards wrote: > On 2016-03-05, Wildman <best_lay@yahoo.com> 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. > > You'll have to be a lot more specific about what you mean by "add an > icon to a window". Do you just want to display an .ico file within a > window? Sorry. I am talking about the titlebar or system icon. -- <Wildman> GNU/Linux user #557453
[toc] | [prev] | [next] | [standalone]
| From | Rick Johnson <rantingrickjohnson@gmail.com> |
|---|---|
| Date | 2016-03-09 08:39 -0800 |
| Message-ID | <02d1cfd3-d9a3-4c5b-83b0-48cb64c30309@googlegroups.com> |
| In reply to | #104106 |
On Saturday, March 5, 2016 at 12:08:27 PM UTC-6, Grant Edwards wrote: > You'll have to be a lot more specific about what you mean by "add an > icon to a window". Do you just want to display an .ico file within a > window? I think he wants to use his *OWN* icon on a window's title bar, instead of the default icon that Tkinter uses. It would help if he posted the code he tried, along with any exceptions that were raised.
[toc] | [prev] | [next] | [standalone]
| From | Wildman <best_lay@yahoo.com> |
|---|---|
| Date | 2016-03-05 12:10 -0600 |
| Subject | Re: Adding Icon To Tkinter Window - Followup |
| Message-ID | <qMKdnSPI4_llvUbLnZ2dnUU7-eOdnZ2d@giganews.com> |
| In reply to | #104104 |
On Sat, 05 Mar 2016 10:47:09 -0600, Wildman 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.
I found this and it works in Linux but only with black
and white xbm images (I would prefer color):
root.wm_iconbitmap('@myicon.xbm')
I found some info in a forum that talked about putting
a color icon in a Label on a separate window and passing
that to the main window as the icon. But there were no
code examples or explanations. So far I have not been
able to figure it out. I would appreciate any help.
--
<Wildman> GNU/Linux user #557453
"Be at war with your vices, at peace with your neighbors,
and let every new year find you a better man."
-Benjamin Franklin
[toc] | [prev] | [next] | [standalone]
| From | Christian Gollwitzer <auriocus@gmx.de> |
|---|---|
| Date | 2016-03-05 19:36 +0100 |
| Subject | Re: Adding Icon To Tkinter Window - Followup |
| Message-ID | <nbf8pc$783$1@dont-email.me> |
| In reply to | #104107 |
Am 05.03.16 um 19:10 schrieb Wildman:
> On Sat, 05 Mar 2016 10:47:09 -0600, Wildman 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.
>
> I found this and it works in Linux but only with black
> and white xbm images (I would prefer color):
>
> root.wm_iconbitmap('@myicon.xbm')
iconphoto is the newer API for color icons. I am a bit surprised that it
is not wrapped in Tkinter, which is odd. You can still call it via eval:
import Tkinter
from Tkinter import Tk
root = Tk()
img = Tkinter.Image("photo", file="appicon.gif")
root.call('wm','iconphoto',root._w,img)
If you Tk is recent enough (8.6, you can find out by doing
root.eval('info patchlevel')), you can use .png files in addition to
.gif. If you need to read other image files, look into PIL and ImageTk.
Christian
[toc] | [prev] | [next] | [standalone]
| From | Wildman <best_lay@yahoo.com> |
|---|---|
| Date | 2016-03-05 23:53 -0600 |
| Subject | Re: Adding Icon To Tkinter Window - Followup |
| Message-ID | <bKOdnRxActZ2WEbLnZ2dnUU7-IudnZ2d@giganews.com> |
| In reply to | #104108 |
On Sat, 05 Mar 2016 19:36:19 +0100, Christian Gollwitzer wrote:
> Am 05.03.16 um 19:10 schrieb Wildman:
>> On Sat, 05 Mar 2016 10:47:09 -0600, Wildman 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.
>>
>> I found this and it works in Linux but only with black
>> and white xbm images (I would prefer color):
>>
>> root.wm_iconbitmap('@myicon.xbm')
>
> iconphoto is the newer API for color icons. I am a bit surprised that it
> is not wrapped in Tkinter, which is odd. You can still call it via eval:
>
> import Tkinter
> from Tkinter import Tk
> root = Tk()
> img = Tkinter.Image("photo", file="appicon.gif")
> root.call('wm','iconphoto',root._w,img)
The above worked perfectly. Thank you very much.
> If you Tk is recent enough (8.6, you can find out by doing
> root.eval('info patchlevel')), you can use .png files in addition to
> .gif. If you need to read other image files, look into PIL and ImageTk.
>
> Christian
According to "root.eval('info patchlevel')" I have version 8.6.2.
PNG worked. That is good because PNG is a common file type for
Linux icons.
--
<Wildman> GNU/Linux user #557453
The cow died so I don't need your bull!
[toc] | [prev] | [next] | [standalone]
| From | Christian Gollwitzer <auriocus@gmx.de> |
|---|---|
| Date | 2016-03-06 10:16 +0100 |
| Subject | Re: Adding Icon To Tkinter Window - Followup |
| Message-ID | <nbgscf$tlf$1@dont-email.me> |
| In reply to | #104120 |
Am 06.03.16 um 06:53 schrieb Wildman:
> On Sat, 05 Mar 2016 19:36:19 +0100, Christian Gollwitzer wrote:
>> import Tkinter
>> from Tkinter import Tk
>> root = Tk()
>> img = Tkinter.Image("photo", file="appicon.gif")
>> root.call('wm','iconphoto',root._w,img)
>
> The above worked perfectly. Thank you very much.
Then you should try if it works also with the last line replaced as
root.wm_iconphoto(True, img)
(as Serhiy and Terry wrote). My system python which I used to test this
was just too old to wrap iconphoto, yours should be up to date.
Christian
> According to "root.eval('info patchlevel')" I have version 8.6.2.
> PNG worked. That is good because PNG is a common file type for
> Linux icons.
PS: 8.6.2 is from mid 2014, that's OK - though we've had a brand new
release (8.6.5) in February 2016
[toc] | [prev] | [next] | [standalone]
| From | Wildman <best_lay@yahoo.com> |
|---|---|
| Date | 2016-03-06 10:30 -0600 |
| Subject | Re: Adding Icon To Tkinter Window - Followup |
| Message-ID | <rPudnXgNiJSMxkHLnZ2dnUU7-cdh4p2d@giganews.com> |
| In reply to | #104126 |
On Sun, 06 Mar 2016 10:16:55 +0100, Christian Gollwitzer wrote:
> Am 06.03.16 um 06:53 schrieb Wildman:
>> On Sat, 05 Mar 2016 19:36:19 +0100, Christian Gollwitzer wrote:
>>> import Tkinter
>>> from Tkinter import Tk
>>> root = Tk()
>>> img = Tkinter.Image("photo", file="appicon.gif")
>>> root.call('wm','iconphoto',root._w,img)
>>
>> The above worked perfectly. Thank you very much.
>
> Then you should try if it works also with the last line replaced as
>
> root.wm_iconphoto(True, img)
That does not work...
$ ./makexface.py
Traceback (most recent call last):
File "./makexface.py", line 236, in <module>
root.wm_iconphoto(True, img)
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1897, in __getattr__
return getattr(self.tk, attr)
AttributeError: wm_iconphoto
> (as Serhiy and Terry wrote). My system python which I used to test this
> was just too old to wrap iconphoto, yours should be up to date.
>
> Christian
>
>
>> According to "root.eval('info patchlevel')" I have version 8.6.2.
>> PNG worked. That is good because PNG is a common file type for
>> Linux icons.
>
> PS: 8.6.2 is from mid 2014, that's OK - though we've had a brand new
> release (8.6.5) in February 2016
I am using the latest release that is offered in the Debian
repository but I will look into upgrading from other sources.
Thanks for the info.
--
<Wildman> GNU/Linux user #557453
The cow died so I don't need your bull!
[toc] | [prev] | [next] | [standalone]
| From | Serhiy Storchaka <storchaka@gmail.com> |
|---|---|
| Date | 2016-03-09 19:09 +0200 |
| Subject | Re: Adding Icon To Tkinter Window - Followup |
| Message-ID | <mailman.87.1457543454.15725.python-list@python.org> |
| In reply to | #104152 |
On 06.03.16 18:30, Wildman via Python-list wrote:
> That does not work...
>
> $ ./makexface.py
> Traceback (most recent call last):
> File "./makexface.py", line 236, in <module>
> root.wm_iconphoto(True, img)
> File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1897, in __getattr__
> return getattr(self.tk, attr)
> AttributeError: wm_iconphoto
This works in Python 3.x. In 2.7 you should use
root.tk.call('wm', 'iconphoto', str(root), '-default', img, ...)
Note that it is worth to specify images for several different sizes (up
to 128x128 for OS X).
[toc] | [prev] | [next] | [standalone]
| From | Joaquin Alzola <Joaquin.Alzola@lebara.com> |
|---|---|
| Date | 2016-03-09 17:14 +0000 |
| Subject | RE: Adding Icon To Tkinter Window - Followup |
| Message-ID | <mailman.91.1457548807.15725.python-list@python.org> |
| In reply to | #104152 |
> root.wm_iconphoto(True, img) What are the images format allowed? This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt.
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2016-03-05 18:38 +0000 |
| Message-ID | <mailman.230.1457203177.20602.python-list@python.org> |
| In reply to | #104104 |
On 05/03/2016 16:47, 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. > Would you please be kind enough to read this http://www.catb.org/esr/faqs/smart-questions.html. Then tell us exactly what you are trying to achieve, how you are trying to achieve it and the error that you get, including the complete traceback if there is one. TIA. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence
[toc] | [prev] | [next] | [standalone]
| From | Wildman <best_lay@yahoo.com> |
|---|---|
| Date | 2016-03-05 12:50 -0600 |
| Message-ID | <HLidnWPnssPkt0bLnZ2dnUU7-bWdnZ2d@giganews.com> |
| In reply to | #104109 |
On Sat, 05 Mar 2016 18:38:57 +0000, Mark Lawrence wrote: > On 05/03/2016 16:47, 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. >> > > Would you please be kind enough to read this > http://www.catb.org/esr/faqs/smart-questions.html. Then tell us exactly > what you are trying to achieve, how you are trying to achieve it and the > error that you get, including the complete traceback if there is one. > > TIA. Thank you, I will do that. I am new to Python and this group but ignorance is no excuse. In the future I will strive to do better. -- <Wildman> GNU/Linux user #557453
[toc] | [prev] | [next] | [standalone]
| From | Serhiy Storchaka <storchaka@gmail.com> |
|---|---|
| Date | 2016-03-05 21:55 +0200 |
| Message-ID | <mailman.231.1457207749.20602.python-list@python.org> |
| In reply to | #104104 |
On 05.03.16 18:47, 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.
On Windows:
root.wm_iconbitmap(default='myapp.ico')
.ico-file can contain several icons of different size.
Otherwise if TkVersion >= 8.5:
root.wm_iconphoto(True, PhotoImage(file='myapp16.gif'),
PhotoImage(file='myapp32.gif'), ...)
You can specify several icons of different size.
If TkVersion >= 8.5 you can use .png-files.
[toc] | [prev] | [next] | [standalone]
| From | Wildman <best_lay@yahoo.com> |
|---|---|
| Date | 2016-03-05 23:56 -0600 |
| Message-ID | <bKOdnR9ActblW0bLnZ2dnUU7-IsAAAAA@giganews.com> |
| In reply to | #104112 |
On Sat, 05 Mar 2016 21:55:40 +0200, Serhiy Storchaka wrote: > On 05.03.16 18:47, 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. > > On Windows: > > root.wm_iconbitmap(default='myapp.ico') > > .ico-file can contain several icons of different size. > > Otherwise if TkVersion >= 8.5: > > root.wm_iconphoto(True, PhotoImage(file='myapp16.gif'), > PhotoImage(file='myapp32.gif'), ...) > > You can specify several icons of different size. > > If TkVersion >= 8.5 you can use .png-files. Thanks. I will file away the snippets for later use. The code provided by Mr. Gollwitzer is working for me on Linux. -- <Wildman> GNU/Linux user #557453 The cow died so I don't need your bull!
[toc] | [prev] | [next] | [standalone]
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2016-03-05 16:38 -0500 |
| Message-ID | <mailman.233.1457213922.20602.python-list@python.org> |
| In reply to | #104104 |
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
[toc] | [prev] | [next] | [standalone]
| From | Wildman <best_lay@yahoo.com> |
|---|---|
| Date | 2016-03-06 00:04 -0600 |
| Message-ID | <bKOdnR5Actb4VUbLnZ2dnUU7-IudnZ2d@giganews.com> |
| In reply to | #104114 |
On Sat, 05 Mar 2016 16:38:08 -0500, Terry Reedy wrote: > 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. I appreciate your reply. Your code looks interesting but it is over my head right now. I will save it for further study and experimentation. Right now my problem was fixed by using the code posted by Mr. Gollwitzer. -- <Wildman> GNU/Linux user #557453 The cow died so I don't need your bull!
[toc] | [prev] | [next] | [standalone]
| From | Rick Johnson <rantingrickjohnson@gmail.com> |
|---|---|
| Date | 2016-03-09 08:41 -0800 |
| Message-ID | <56c4f4b9-3164-4a5e-80cd-3c82cc891d01@googlegroups.com> |
| In reply to | #104114 |
On Saturday, March 5, 2016 at 3:39:00 PM UTC-6, Terry Reedy wrote: > 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). Yes, because Tkinter is not as cross-platform as it's hyped to be.
[toc] | [prev] | [next] | [standalone]
| From | Wildman <best_lay@yahoo.com> |
|---|---|
| Date | 2016-03-06 00:09 -0600 |
| Message-ID | <bKOdnRlActYzVEbLnZ2dnUU7-IsAAAAA@giganews.com> |
| In reply to | #104104 |
I apologize to the group for my lack of information in my original post. I will do better in the future. I very much want to remain in good standing in this group because of all the knowledgeable people here. Thanks again to everyone that replied and helped me solve my problem. -- <Wildman> GNU/Linux user #557453 The cow died so I don't need your bull!
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web