[英]How can i use an image as a background in Tkinter?
所以我想在 Tkinter 中使用圖像作為我的背景,就像 windows 在桌面上有背景圖像一樣。 這是我的代碼,但它似乎不起作用:
root = tk.Tk()
root.attributes("-fullscreen", True)
background_image=tk.PhotoImage("image")
代碼運行但顯示為白色背景。
這很簡單:這是如何做到的:
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()
只需確保編輯此部分 (file = "image.png") 並使用圖像的路徑名。 最好將其保存在與存儲程序相同的文件夾中,但這不是必需的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.