问题描述
我计划使用 PyInstaller(工作正常)打包应用程序。但是,我在使用 Tkinter 引用我用于标题屏幕的图像路径时遇到问题。
我认为最简单的方法是将标题图像保存在笔记本电脑上的文档文件夹中,然后编写程序以引用该图像的路径。但是,我计划与同事共享该应用程序,因此需要路径名必须是动态的,但最终引用为 /Documents/xxxxx.png
image = Image.open('MG_title.png') #this needs to be updated to include the dynamic pathname irrespective of system / user
#add function to resize Image
def resize_image(event):
new_width = event.width
new_height = event.height
image = copy_of_image.resize((new_width,new_height))
photo = ImageTk.PhotoImage(image)
label.config(image = photo)
label.image = photo #avoid garbage collection
#title page for programme
root = tk.Tk()
root.title('Manchester Giants')
root.resizable(False,False)
w = 600 # popup window width
h = 330 # popup window height
sw = root.winfo_screenwidth()
sh = root.winfo_screenheight()
x = (sw - w)/2
y = (sh - h)/2
root.geometry('%dx%d+%d+%d' % (w,h,x,y))
copy_of_image = image.copy()
photo = ImageTk.PhotoImage(image)
label = Label(root,image = photo)
label.bind('<Configure>',resize_image)
label.pack(fill=BOTH,expand = YES)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)