以下是代码:
img_b64 = """R0lGODlhGAAYAPEAADIyMjMzMzQ0NAAAACH5BAEAAAMALAAAAAAYABgAAAJOnI8Ciu0I4gKvtmXzidoKBXbQBE5iVJZYJpGkQlluisYVnYbVgk/+XcOBBMAebWecFWfMR1Lo+DCNjuD0JcpqZUPmFSbjrbYDGJF8YGQKADs="""
img = PhotoImage(data = img_b64)
close_button = Button(root, image=img, command=root.quit)
close_button.pack(side=LEFT)
root.mainloop()
# def poptk(root):
# img_b64 = """R0lGODlhGAAYAPEAADIyMjMzMzQ0NAAAACH5BAEAAAMALAAAAAAYABgAAAJOnI8Ciu0I4gKvtmXzidoKBXbQBE5iVJZYJpGkQlluisYVnYbVgk/+XcOBBMAebWecFWfMR1Lo+DCNjuD0JcpqZUPmFSbjrbYDGJF8YGQKADs="""
# img = PhotoImage(data = img_b64)
# close_button = Button(root, image=img, command=root.quit)
# close_button.pack(side=LEFT)
# poptk(root)
# root.mainloop()
第一部分是工作代码,但是一旦我将其重构为函数,就无法显示图像,点击也无效。
截图: