简体   繁体   English

在Tkinter中将图像导入为背景

[英]Import an image as a background in Tkinter

I've searched some other questions that many people did ask here about how can someone import an image as a background from Tkinter and I've got to say that I wasm't helped a lot. 我已经搜索了许多人在这里问过的一些其他问题,关于如何从Tkinter导入图像作为背景,我必须说我没有多少帮助。 Let me explain to you my problem. 让我向你解释我的问题。 I have downloaded an image,converted it to gif and save it to my desktop.However can the Tkinter window opens up it does not import the image. 我已经下载了一个图像,将其转换为gif并将其保存到我的桌面。但是,Tkinter窗口打开后它不会导入图像。 Here is my code: 这是我的代码:

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

Are you able to help me? 你能帮帮我吗?

你应该以这种方式使用PhotoImage。

background_image=Tk.PhotoImage(file="C:/Desktop/logo.gif")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM