python下窗体控件传递问题

在窗体上创建了画布,载入图片时在内函数下写可以正常载入,换到另一函数,窗体值传递不过去,无法载入图片,也不报错,不知为何?窗体参数传递有问题?特赐教。

import tkinter as tk
from PIL import Image, ImageTk
gComps = {}

def picresize(p):
    img = PhotoImage(file=r'D:\pythonwork\11.png')
    px=p.create_image(30,150,image = img,anchor =W)#无法载入图片,此段放在main里写,没问题
    return

def main(argv):
    top = Tk()
    top.title('Form1')
    top.geometry('783x358')
    gComps['top'] = top
    style = Style()
    gComps['style'] = style
    Picture1 = Canvas(top, takefocus=1, bg='#FF0000')
    Picture1.place(relx=0.123, rely=0.335, relwidth=0.295, relheight=0.62)
    gComps['Picture1'] = Picture1
    picresize(Picture1)
    top.mainloop()

if __name__ == "__main__":
    main(sys.argv)gComps = {}

因为img是在picresize里的局部变量,main()函数调用不了。
在picresize把img声明成全局变量就可以了
global img