gpt4 book ai didi

python - 在 Tkinter 中导入图像作为背景

转载 作者:太空宇宙 更新时间:2023-11-03 11:05:14 25 4
gpt4 key购买 nike

我搜索了其他一些问题,很多人确实在这里问过关于如何从 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 - 在 Tkinter 中导入图像作为背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21222972/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com