我已经搜索了许多人在这里问过的一些其他问题,关于如何从Tkinter导入图像作为背景,我必须说我没有多少帮助.
让我向你解释我的问题.我已经下载了一个图像,将其转换为gif并将其保存到我的桌面.但是,Tkinter窗口打开后它不会导入图像.
这是我的代码:
import Tkinter as Tk
root = Tk.Tk()
background_image=Tk.PhotoImage("C:/Desktop/logo.gif")
background_label = Tk.Label(root, image=background_image)
background_label.place(x=0, y=0, relwidth=1, relheight=1)
root.wm_geometry("600x400+20+40")
root.title('Menu')
playButton = Tk.Button(root, text='Play', command=root.destroy)
playButton.pack()
root.mainloop()
你能帮帮我吗?
解决方法:
你应该以这种方式使用PhotoImage.
background_image=Tk.PhotoImage(file="C:/Desktop/logo.gif")
标签:python,import,image,tkinter,pygame