Error setting icon for tkinter of python using iconbitmap ()

use the icon of the tkinter settings window to report an error

-sharptkintericonbitmap
from tkinter import *

def main():
    root = Tk()
    root.title("Change Logo")
    root.geometry("350x150")
    root.iconbitmap("python.ico")
    root.mainloop()



if __name__ == "__main__":
    main()

error message:

_tkinter.TclError: bitmap "python.ico" not defined

searched for this question for a long time, some people on stackoverflow also asked, but also did not find the answer, some people said that in the Windows there will be this question
but I used the Linux,python3.5, absolute path, the same error, some people said that this function only supports black and white ico image, but I use the ico picture is black and white.
ask for the Great God.

Mar.19,2021

iconbitmap () the parameter required is the address of the icon.

if your python.ico files are placed in the current directory, it's OK to directly root.iconbitmap ('python.ico') .
if the python.ico files are placed in another directory, such as / home/user/foo/python.ico , use the absolute path, root.iconbitmap (' / home/user/foo/python.ico') .

in short, make sure that the python.ico file exists in your file path.

Menu