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盘拷贝小工具 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)

以上红色代码为需要增加的代码

此外,还需要修改打包的spec文件,在在a.datas,下面添加   [('favicon-20180501101520441.ico','D:\\python_workshop\\python6\\personal_practices\\favicon-20180501101520441.ico','DATA')]。InI

再重新通过PyInstaller -i D:\python_workshop\python6\personal_practices\favicon-20180501101520441.ico -w D:\python_workshop\python6\personal_practices\udisk_copy v6.0.py打包。然后运行,发现一切ok

 

参考:

​http://tieba.baidu.com/p/3060401749​