tkinter图像按钮无法在函数内部工作

时间:2014-11-13 23:09:33

标签: python tk

以下是代码:

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()

第一部分是工作代码,但是一旦我将其重构为函数,就无法显示图像,点击也无效。

截图:

enter image description here

enter image description here

0 个答案:

没有答案