Why isn't .ico file defined when setting window's icon?

前端 未结 12 1569
一整个雨季
一整个雨季 2020-11-27 15:47

When I tried to change the window icon in the top left corner from the ugly red \"TK\" to my own favicon using the code below, Python threw an error:

from tk         


        
12条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 16:17

    Try this:

    from tkinter import *
    import os
    import sys
    
    root = Tk()
    root.iconbitmap(os.path.join(sys.path[0], ''))
    
    root.mainloop()
    

    Note: replace with the name of the ico file you are using otherwise it won't work.

    I have tried this in Python 3. It worked.

提交回复
热议问题