Set window icon



  • 5 Answer(s)

    The answer is:

        The  favicon.ico in the same folder as your script or, namely, on your path. Put in the full pathname.

    For example, this works:

    from tkinter import *
    root = Tk()
     
    root.iconbitmap(r'c:\Python32\DLLs\py.ico')
    root.mainloop()
    

    Example 2:

    from tkinter import *
    root = Tk()
     
    root.iconbitmap('py.ico')
    root.mainloop()
    
    Answered on November 28, 2018.
    Add Comment

    You can try this solution:

     The correct path is:

    imgicon = PhotoImage(file=os.path.join(sp,'myicon.gif'))
    root.tk.call('wm', 'iconphoto', root._w, imgicon)
    

    where sp is the script path, and root the Tk root window.

    You can refre tihs link:https://forums.fedoraforum.org/showthread.php?297279-Python3-Tkinter-icon-What-gives!

    Answered on November 28, 2018.
    Add Comment

    The best solution is:

    #!/usr/bin/env python
    import tkinter as tk
     
    class AppName(tk.Frame):
        def __init__(self, master=None):
            tk.Frame.__init__(self, master)
            self.grid()
            self.createWidgets()
     
        def createWidgets(self):
            self.quitButton = tk.Button(self, text='Quit', command=self.quit)
            self.quitButton.grid()
     
    app = AppName()
    app.master.title('Title here ...!')
    app.master.iconbitmap('icon.ico')
    app.mainloop()
    
    Answered on November 28, 2018.
    Add Comment

    You must not have favicon.ico in the same folder as your script or, namely, on your path. Put in the full pathname. For example, this works:

    from tkinter import *
    root = Tk()
    
    root.iconbitmap(r'c:\Python32\DLLs\py.ico')
    root.mainloop()

    But this blows up with your same error:

    from tkinter import *
    root = Tk()
    
    root.iconbitmap('py.ico')
    root.mainloop()
    Answered on February 25, 2019.
    Add Comment

    1.Set the hIcon member of the WNDCLASSEX structure used to register your main window to an appropriate value like the following code does. (Where EXAMPLE_ICON is your icon resource)

    WNDCLASSEX wcex = {}; 
    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.style = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc = WndProc;
    wcex.cbClsExtra = 0;
    wcex.cbWndExtra = 0;
    wcex.hInstance = hInstance;
    wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(EXAMPLE_ICON));
    wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
    wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    wcex.lpszMenuName = nullptr;
    wcex.lpszClassName = "ExampleIconWindowClass";
    wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRE
    SOURCE(IDI_APPLICATION));
    Answered on April 17, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.