如何在 Tkinter 中的文本下获取图像?

How do I get image under the text In Tkinter?

我最近开始学习 Python 和 Tkinter。我大约一个月前开始。但让我们进入正题。

我已经做了1天的随机软件(所以不要嘲笑),代码已经准备好了,但我仍然需要制作应用程序本身,所以我一直在做,但面临制作背景更改按钮时出现问题。我制作了将背景更改为颜色或图片的按钮。

正常的颜色效果很好,但图像看起来很奇怪。我从按钮中看到图像,但问题是,当我单击按钮时,图像显示 OVER 文本、条目等。

适用于不变图片的“代码修复”:

Tkinter.Label(window, i=bgimg, compound=Tkinter.CENTER).pack()

我没见过多少人有这个问题。我看到了一个,它起作用了(如果我有一个不可更改的背景),但是因为我有按钮,所以代码根本不关心它。 (该代码对不变的图片有帮助。)

代码如下:

from tkinter import *
import tkinter as tk
import tkinter


window=Tk()
bgimg= tk.PhotoImage(file = "C:\Users\Hoze\Downloads\Hoze (1).png")


btn=Button(window, text="Convert", fg='blue', padx=50)
btn.place(x=220, y=380)

def myClick():
    myLabel = Label(window, window.configure(bg='red'))
    myLabel.pack()
btn=Button(window, text="Red", fg='red', padx=20, command=myClick)
btn.place(x=520, y=150)

def myClick():
    myLabel = Label(window, window.configure(bg='blue'))
    myLabel.pack()
btn=Button(window, text="Blue", fg='blue', padx=19, command=myClick)
btn.place(x=520, y=200)

def myClick():
    myLabel = Label(window, window.configure(bg='green'))
    myLabel.pack()
btn=Button(window, text="Green", fg='green', padx=15, command=myClick)
btn.place(x=520, y=300)

def myClick():
    myLabel = Label(window, window.configure(bg='orchid'))
    myLabel.pack()
btn=Button(window, text="Default", fg='orchid', padx=11, command=myClick)
btn.place(x=520, y=250)


# Here is the problem, and here is the code that
# put the picture like it should UNDER the text
# (if i put the code to the start)
# (But then it does't change to the other colours)

def myClick():
    myLabel= Label(window, i=bgimg, )
    myLabel.pack()
btn=Button(window, text="Cool", fg='aqua', padx=11, command=myClick)
btn.place(x=520, y=250)

# If i now run this code, the picture will come
# on top of the text.

lbl=Label(window, text="  Extract a word here, \n that you want make secret!", fg='blue', font=("Helvetica", 16))
lbl.place(x=166 , y=50)
lbl=Label(window, text="Your Secret Word is: ", fg='blue', font=("Helvetica", 10))
lbl.place(x=120, y=300)

txtfld=Entry(window, text="This is Entry Widget", bd=5)
txtfld.place(x=234, y=150)

window.title('Hoze Secret Lenguage Converter')
window.geometry("600x500+10+10")
window.minsize(600, 500)
window.maxsize(600, 500)
window.iconbitmap("C:\Users\Hoze\Music\Coding\Project Secret\favicon.ico")
window.configure(bg='green')

window.mainloop() 

这应该让你的东西

#import tkinter as tk
from email.mime import image
from tkinter import *


window=Tk()
bgimg= PhotoImage(file = "C:\Users\Hoze\Downloads\Hoze (1).png")
myLabel= Label(window, i=bgimg )
myLabel.pack()
myLabel.pack_forget()

btn=Button(window, text="Convert", fg='blue', padx=50)
btn.place(x=220, y=380)




def myClick():
    myLabel.pack_forget()
    window.configure(bg='red')

btn=Button(window, text="Red", fg='red', padx=20, command=myClick)
btn.place(x=520, y=150)

def myClick():
    myLabel.pack_forget()
    window.configure(bg='blue')
    
btn=Button(window, text="Blue", fg='blue', padx=19, command=myClick)
btn.place(x=520, y=200)

def myClick():
    myLabel.pack_forget()
    window.configure(bg='green')
    
btn=Button(window, text="Green", fg='green', padx=15, command=myClick)
btn.place(x=520, y=300)

def myClick():
    myLabel.pack_forget()
    window.configure(bg='orchid')

    
btn=Button(window, text="Default", fg='orchid', padx=11, command=myClick)
btn.place(x=520, y=250)


#Here is the problem, and here is the code that put the picture like it should UNDER the text (if i put the code to the start)(But then it does't change to the other colours)
def myClick():
    myLabel.pack()

btn=Button(window, text="Cool", fg='aqua', padx=11, command=myClick)
btn.place(x=520, y=250)
#If i now run this code, the picture will come on top of the text. I hope yall get it, im kinda new
#

lbl=Label(window, text="  Extract a word here, \n that you want make secret!", fg='blue', font=("Helvetica", 16))
lbl.place(x=166 , y=50)
lbl=Label(window, text="Your Secret Word is: ", fg='blue', font=("Helvetica", 10))
lbl.place(x=120, y=300)

txtfld=Entry(window, text="This is Entry Widget", bd=5)
txtfld.place(x=234, y=150)

window.title('Hoze Secret Lenguage Converter')
window.geometry("600x500+10+10")
window.minsize(600, 500)
window.maxsize(600, 500)
window.iconbitmap("C:\Users\Hoze\Music\Coding\Project Secret\favicon.ico")
window.configure(bg='green')

window.mainloop()