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

前端 未结 12 1490
一整个雨季
一整个雨季 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:16

    #!/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()
    

    it should work like this !

提交回复
热议问题