Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何将图像用作按钮功能(Tkinter)_Python_Tkinter_Uibutton_Display_Photoimage - Fatal编程技术网

Python 如何将图像用作按钮功能(Tkinter)

Python 如何将图像用作按钮功能(Tkinter),python,tkinter,uibutton,display,photoimage,Python,Tkinter,Uibutton,Display,Photoimage,原始代码: search_button = Button(Frame3, text="Search", command=lambda: displaySelected(), bg="black", fg="white", font=('Arial', 10),padx=5,pady=5) search_button.place(x=210, y=190) 原始输出是什么样的: DisplaySelected()的作用是: 我所尝试

原始代码:

search_button = Button(Frame3, text="Search", command=lambda: displaySelected(), bg="black", fg="white", font=('Arial', 10),padx=5,pady=5)
search_button.place(x=210, y=190)
原始输出是什么样的:

DisplaySelected()的作用是:

我所尝试的:

search_pic = PhotoImage(file="search.png")
search_button = Button(Frame3, image=search_pic, command=lambda: displaySelected(), bg="black", fg="white", font=('Arial', 10),padx=5,pady=5)
search_button.place(x=210, y=190)

基本上,我想做同样的功能,只是为了更好的外观,我希望用一个png文件代替“搜索”按钮。但是,当我运行代码时,由于某种原因,我的png没有显示?

这是否回答了您的问题@acw1668不,哈哈,谢谢你!!我试着按照youtube教程制作一个具有按钮功能的图像。。。但是,它们都显示为.pack()。我的代码require.place()和我的图像不在根目录中,而是在Frame3中。代码是否在函数中?如果是,则与链接中的问题相同。