def resource_path(self, relative): if hasattr(sys, "_MEIPASS"): return os.path.join(sys._MEIPASS, relative) return os.path.join(relative) def copy_GUI(self): root = tkinter.Tk() root.title( " U disk copy gadget v6.0 " ) root.geometry("400x260") icopath = self.resource_path(r"D:\python_workshop\python6\personal_practices\favicon-20180501101520441.ico") if os.path.exists(icopath): root.iconbitmap(icopath)
The red code above is the code that needs to be added
In addition, you need to modify the packaged spec file, add [ (' favicon-20180501101520441.ico ' ,'D:\\ python_workshop \\python6\\personal_practices\\favicon-20180501101520441.ico',' DATA') ]. InI
Repackage through PyInstaller -w D:\python_workshop\python6\personal_practices\udisk_copy v6.0.py. Then run it and find that everything is ok
refer to: