【问题标题】:How can i use an image as a background in Tkinter?如何在 Tkinter 中使用图像作为背景?
【发布时间】:2021-09-01 03:21:39
【问题描述】:

所以我想在 Tkinter 中使用图像作为我的背景,就像 windows 在桌面中具有背景图像一样。这是我的代码,但它似乎不起作用:

root = tk.Tk()
root.attributes("-fullscreen", True)
background_image=tk.PhotoImage("image")

代码运行,但显示为白色背景。

【问题讨论】:

  • 也许这可以帮助你youtu.be/WurCpmHtQc4
  • 可能是因为您对那张图片基本上什么都不做?您还必须将该图像放置在某个地方,例如标签中

标签: python python-3.x user-interface tkinter settings


【解决方案1】:

这很简单!操作方法如下:

from tkinter import *
root = Tk()
root.geometry("400x400")
bg = PhotoImage(file = "image.png")
label1 = Label(root, image = bg)
label1.place(x = 0, y = 0)
root.mainloop()

只需确保编辑此部分(文件 =“image.png”)并使用图像的路径名即可。最好将其保存在与您的程序存储相同的文件夹中,尽管这不是必需的。

【讨论】:

猜你喜欢
  • 2012-04-26
  • 2021-07-12
  • 1970-01-01
  • 2019-04-10
  • 1970-01-01
  • 2012-07-16
  • 2020-06-02
相关资源
最近更新 更多