Within a kind of application of the style of a Text Editor, I open the typical "Help" and "About" windows.
Both windows are made using the Toplevel Tkinter widget. And I would like to put an icon that appeared in the taskbar as I have done for the main window of the application (the root).
For the main window (root), I have set the icon in this way (in this case, "self", refers to ROOT):
self.img_logo = PhotoImage(file='img/anonvicom_logo.png')
self.call('wm', 'iconphoto', self, self.img_logo)
I have tried to do the same in the configuration of the two mentioned Toplevel but, apparently, because of the ERROR that I get the method "call ()" is not available for TopLevel widgets.
I've tried, too, to put it this way (for example, for the Toplevel "ayuda_top"):
ayuda_top.iconwindow('img/anonvicom_logo.png')
or, like this:
ayuda_top.iconwindow(pathName='img/anonvicom_logo.png')
But it gives me something like this ERROR:
TclError: bad window path name "img/anonvicom_logo.png"
Also, I used:
acerca_top.iconbitmap('@img/anonvicom_logo.xbm')
But this way, apart from putting the image in Black / White and negative, now, I'm giving this ERROR too:
TclError: error reading bitmap file "img/anonvicom_logo.xbm"
By giving me this ERROR, the execution stops.
The "@" is because, apparently, for Linux routes, it would be necessary to put it, and, if not, I get this message:
TclError: bitmap "img/anonvicom_logo.xbm" not defined
NOTE : As a curiosity, the ERROR of " TclError: error reading bitmap file "img/anonvicom_logo.xbm"
", occurs when I run the application by the Visual Studio Code. If I execute it through the Sublime Text, or by the interpreter of the terminal, it opens without any complaint.
So, how to put a window icon for Toplevel widgets whether or not the same icon as the icon in the parent window?
If you want to put the same icon of the main window, is there any way, too, to inherit its icon for the Toplevel son windows?
Employee environment: python 2.7.x, Linux Ubuntu 16.04, Tkinter.
Edited
For the one that interests you as I define the self (the root object), there it goes:
from Tkinter import *
class MiTkinter(Tk):
def __init__(self, *args, **kwargs):
Tk.__init__(self, *args, **kwargs)
self.img_logo = PhotoImage(file='img/anonvicom_logo.png')
self.call('wm', 'iconphoto', self, self.img_logo)
# y después todo el código que haga falta
# ...
if __name__ == '__main__':
# Tk (Raíz) objeto raíz por defecto
# ==========================================================
root = MiTkinter()
# etc, etc, ...